PYTHON BASICSChapter 3 · Loops and iteration
The for loop
Sometimes you want to do the same thing many times, say hello to every cloud in the sky. Instead of copying a line over and over, a for loop repeats it for you, once per item.
Worked example
How it reads
- for cloud in range(3) means "for each of 3 turns, call the current turn cloud"
- The indented line is the part that repeats. Python knows it belongs to the loop because of the spaces
- range(3) counts 0, 1, 2, three numbers, starting at zero

Cloud tip: Loops start counting at 0, not 1. Nearly every programmer has tripped on this, now you won't.


