Loop Control Statements II-103
5. Explain the steps for performing counter-controlled repetition.
Ans: Steps in counter-controlled loop are as follows:
1. Loop variable: It is a variable used in the loop.
2. Initialization: It is the first step in which starting/final value is assigned to the loop variable. Each
time the updated value is checked by the loop itself.
3. Incrimination/Decrementation: It is the numerical value added or subtracted to the variable in
each round of the loop. The updated value is compared with the final value and if it is found less
than final value, the steps in the loop are executed.
6. What do you mean by Sentinel-controlled repetition?
Ans: This is also called 'indefinite repetition'; one cannot estimate how many iterations would be
required. In this type loop, termination happens based on certain condition using decision-making
7. Give a programming example that supports Sentinel-controlled loop. Example is to find
total odd and even numbers until 0 is pressed using 'while' loop.
printf("Enter the number: ");
printf("\nEntered number %d is even ",x);
printf("\n Entered number %d is odd ",x);
printf("\n\n Enter the number:");
printf("\n %d %d',even,odd);
M06_ITL-ESL4791_02_SE_C06.indd 103 12/22/2012 5:02:19 PM