The Foundry · Level 3

Loops & Patterns

Do a lot with a little. Tell the computer one move, then say how many times to repeat it.

One move, said many times

Imagine you are holding a pen on a big sheet. To draw a square you do the same thing four times: move forward a bit, then turn. A is how you tell a computer to repeat a move without writing it out over and over.

The same square, the long way and the loop way
# the long way: typing every line
move forward
turn 90 degrees
move forward
turn 90 degrees
move forward
turn 90 degrees
move forward
turn 90 degrees

# the loop way: same picture, way less to write
repeat 4 times:
    move forward
    turn 90 degrees
A loop repeats instructions. Both versions above draw the exact same square. The loop just says it once and tells the computer how many times to go around.

← The Foundry · every fact here is real. Tap the underlined words to dig deeper.