← the wiki

Loop

Code that repeats — for a set count (for) or while a condition holds (while).

A loop runs the same lines again and again so you don't have to copy-paste them. for i in range(1000000) does something a million times; while lives > 0 keeps going until a condition changes.

Loops are why computers feel powerful: the work of repeating belongs to the machine, and one well-written loop replaces an army of tired humans.

The best way to make it stick: watch it run. Start an interactive lesson →