Skip to main content

Lesson 3.2: Repeat While a Rule Is True

A while loop repeats as long as its condition is true. The condition is checked before each repeat. If it starts false, the body does not run.

Something in the loop must normally move the condition toward false. If count < 4 controls the loop, changing count by 1 in the body can eventually stop it. Without that change, the condition stays true and the loop does not stop by itself.

The Telemark runner has an operation limit. It stops a program that performs too many operations and asks you to inspect the loop. This protects the page, but the loop condition still needs a real fix.

Guided practice

Set count to 0. While count < 4, print count and change it by 1. Predict the printed values and the final stored value.

Use Step to find when the condition is checked and when the variable changes. Move the change block outside the loop and run again. Read the safety message, then put the change back where it belongs.

Loading the block workspace...

Ready to move on?

Only mark complete if you genuinely understand the material. Your progress will be saved in this browser.

Stuck on this lesson?

Ask about anything on this page. It can see which lesson you have open and which part you are reading.