Loops and choices

Try itDoing it again

A loop can also stop when something changes. This slime keeps jumping until the hero comes near.

repeat until the
end

How to read it

In the last chapter, an if asked a question once. This loop asks a question every time it goes round: is the hero near?

The answerWhat the slime does
NoGoes round again: jump, wait.
YesLeaves the loop, and carries on with the step after end.

Near means within 3 blocks.

Try it

  1. Press Play Play this script. The slime jumps and jumps. The hero is too far away.
  2. Click the little game, so the arrow keys work.
  3. Hold the right arrow key to walk the hero toward the slime.
  4. Stop when the slime says "Oh! Hello."

The jumping has stopped for good. The loop is over, and the script has run out of steps.

This section ticks itself when you press Play.

Press Play in the code box to finish this section.