Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 4 of 8

One block inside another

Show on a big screen

6 min

Text size

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…

Try the lab to finish this lesson.