Sentinel and Counter Controlled Loop
Sentinel and Counter Controlled Loop
Loop
Counter Controlled Loop
• definite repetition loop
• number of iterations is known before the loop begins to
execute
• Components:
1. a control variable.
2. the increment (or decrement) value by which the control
variable is modified at each iteration of the loop.
3. the loop terminating condition that checks if looping
should continue.
Example: Printing the first 10 natural numbers.
Example:
Event-Controlled loop
• loop an action is repeated until a certain event occurs
• Types:
1. Sentinel-controlled loop
2. End-of-file controlled loop
3. Flag controlled loop
Sentinel Controlled Loop
• indefinite repetition loop
• number of iterations is not known before the loop starts
executing
• sentinel value is used to change the loop control
expression from true to false