Pseudo Code Iteration Control Structure

Sequence and selection are control structures we have already used. Looping also called Iteration is another powerful control structure. Looping allows us to execute the same instruction(s) (typically with different data sets) over and over using the same code.

Pseudo code to print all the numbers between 1 and 10

Counter = 1

Do as long as Counter is <= 10
    Print counter
    Counter = Counter + 1
End loop
 

Pseudo code to print the sum of numbers between 1 and 1, and then the sum of numbers between 1 and 2, and then 1 and 3, and so on.

Counter = 1
Total = 0
 
Do until Counter > 10
    Total = Total + Counter
    Output “Sum of numbers between 1 and “ & Counter & “ = “ & Total
    Counter = Counter + 1
End Loop
 
Output Total

Note: Something must happen inside the loop so that the result of the condition changes. If the condition DOES NOT change you will be in an infinite loop.