Practice Iteration in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

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.

Do this again and again until some condition is met, then move on to the next step.

Example 1

easy
Trace: FOR i = 1 TO 4: OUTPUT i * 2.

Example 2

medium
Trace: SET count = 0. SET n = 1. WHILE n <= 10: IF n MOD 2 == 0 THEN count = count + 1. n = n + 1. OUTPUT count.

Example 3

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

Example 4

easy
Trace this loop: SET total = 2. REPEAT 4 TIMES: SET total = total + 3. OUTPUT total.