Iteration CS Thinking Example 3

Follow the full solution, then compare it with the other examples linked below.

Example 3

easy
Write pseudocode using a loop to output the numbers 5, 10, 15, 20, 25.

Solution

  1. 1
    Step 1: Use a FOR loop: FOR i = 1 TO 5: OUTPUT i * 5.
  2. 2
    Step 2: Alternatively: FOR i = 5 TO 25 STEP 5: OUTPUT i.

Answer

FOR i = 1 TO 5: OUTPUT i * 5.
Loops avoid writing repetitive code. Instead of five separate OUTPUT statements, one loop handles all five outputs.

About Iteration

Repeating a block of instructions multiple times until a stopping condition is satisfied. Iteration is one of the three fundamental control structures (along with sequence and selection) and is implemented through while loops, for loops, and other looping constructs.

Learn more about Iteration โ†’

More Iteration Examples