Skip to content
Exit presentation

Programming with Blocks II

One block inside another

A counter must go up, and stop at 3. That needs a repeat and an if together.

An if holds a repeat. The repeat holds add 1.
Step 1 of 4
  1. An if holds a repeat. The repeat holds add 1.
  2. Step into the if. Check the question.
  3. Step into the repeat.
  4. 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.

The same three blocks nested two ways
ProgramWhat it says
A: if outsideIf score is less than 3, repeat 3 times: add 1.
B: repeat outsideRepeat 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…

Jump to lesson

This track

  1. 0 Start here
  2. 1 A box with a name on it
  3. 2 Changing what is in the box
  4. 3 Waiting for something to happen
  5. 4 One block inside another
  6. 5 Plan it before you build it
  7. 6 The big picture
  8. 7 Track quiz

Other tracks