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.
Do this again and again until some condition is met, then move on to the next step.
Example 1
easyTrace: FOR i = 1 TO 4: OUTPUT i * 2.
Example 2
mediumTrace: 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
easyWrite pseudocode using a loop to output the numbers 5, 10, 15, 20, 25.
Example 4
easyTrace this loop: SET total = 2. REPEAT 4 TIMES: SET total = total + 3. OUTPUT total.