Iteration (Looping)
Post date: 09-Jan-2015 04:53:48
Iteration (Looping)
Iteration (Looping)
Introduction
Introduction
Iteration is also referred to as looping or repetition. Its designed to execute the same block of code again and again until a certain condition is fulfilled.
The three main looping controls are:-
- The WHILE Loop
- The REPEAT....UNTIL Loop
- The FOR Loop
The WHILE Loop
The WHILE Loop
The "WHILE" loop is used if a condition has to be met before the statements within the loop are executed.
General Format
WHILE condition DO
statement
ENDWHILE
The REPEAT....UNTIL loop
The REPEAT....UNTIL loop
The REPEAT....UNTIL loop allows the statements within it to be executed at least once since the condition is tested at the end of the loop.
General Format
REPEAT
statements
UNTIL <condition>
The FOR Loop
The FOR Loop
The FOR loop is used in circumstances where the execution of the chosen statements has to be repeated a predetermined number of times.
General Format
//pseudocode for 'FOR" loop that counts from the lower limit
FOR loop variable = lower limit to upper limit DO
statements
ENDFOR
//pseudocode for a 'FOR' loop that counts from the upper limit down to lower limit
FOR loop variable = upper limit DOWN TO lower limit DO
statements;
ENDFOR