LightMySky

Programming with Loops and Variables

Design and debug programs that use repetition, selection and variables: repeat actions with loops, branch with if-blocks, keep score in a variable, and break a bigger problem into smaller parts that can be programmed one at a time

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • Use a loop instead of repeating the same blocks (e.g., 'repeat 4' to draw a square)
  • Use an if-block so the program responds to input (e.g., 'if the sprite touches the wall, bounce')
  • Store and update a value in a variable, such as a score that goes up or a countdown timer

The lesson

A loop repeats the same steps for you. Instead of stacking blocks like 'move' and 'turn' over and over, you use one loop that says 'repeat 4' and put the steps inside it.

repeat 4moveturn
The repeat block runs 'move' and 'turn' four times, so you never write those two steps four separate times.

An if-block lets your program react instead of just repeating. It checks something first, like 'is the sprite touching the wall?' If that is true, the steps inside run. If not, they are skipped.

Try it together

Every time the cat in a game catches a fish, the code adds 1 to a variable called score. The variable starts at 0, and after three catches it holds 3.

catch 11catch 22catch 33
Good to know

Big programs are easier to build in small pieces. Get the loop working first, then add the if-block, then add the variable. Test each piece before you add the next one.

Loops repeat steps, if-blocks react to what happens, and variables remember numbers that change, so build and test each piece one at a time.

Watch it

Where it sits

Learn first

This opens up

Nothing builds on it yet.

Where this leads

Jobs that lean on this skill. Follow one to see everything it is built on.

Then practise

8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Programming with Loops and Variables · Computing, ages 8 to 11 · LightMySky