One block inside another
A counter must go up, and stop at 3. That needs a repeat and an if together.
Step 1 of 4
- An if holds a repeat. The repeat holds add 1.
- Step into the if. Check the question.
- Step into the repeat.
- Run add 1 three times, then step back out.
An if block runs its blocks only when its question is yes. Putting one block inside another is called nesting.
Rule: Nesting puts one block inside another. The outside block decides whether, and how often, the inside runs.
| Program | What it says |
|---|---|
| A: if outside | If score is less than 3, repeat 3 times: add 1. |
| B: repeat outside | Repeat 3 times: if score is less than 3, add 1. |
Start at 0. Both finish at 3.
Start at 1. A finishes at 4. B finishes at 3.
A checks once: 1 is less than 3. Then it adds 1 three times: 2, 3, 4.
B checks before each add. At 1 it adds: 2. At 2 it adds: 3. At 3 the check fails.
From 1, only B stops at 3.
Slide the start score. Find where A and B differ.
Loading lab…