Iteration Examples in CS Thinking
Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Iteration.
This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.
Concept 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.
Read the full concept explanation βHow to Use These Examples
- Read the first worked example with the solution open so the structure is clear.
- Try the practice problems before revealing each solution.
- Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea: Loops let you do repetitive tasks without writing repetitive code.
Common stuck point: The loop must have a way to stopβevery iteration should progress toward the stopping condition.
Worked Examples
Example 1
easySolution
- 1 Step 1: i = 1: output 2. i = 2: output 4.
- 2 Step 2: i = 3: output 6. i = 4: output 8.
- 3 Step 3: Loop ends after i = 4. Outputs: 2, 4, 6, 8.
Answer
Example 2
mediumPractice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
easyExample 2
easyRelated Concepts
Background Knowledge
These ideas may be useful before you work through the harder examples.