Codele / Programming basics
For loops
When you know how many times to repeat something, a for loop does the counting for you. A counter goes up by itself, one round at a time.
- A for loop repeats lines a known number of times.
- The counter (often called i) goes up by itself after every round.
- Each trip through the loop is called a round (or an iteration).
- Python’s range(1, 5) counts 1, 2, 3, 4. It stops before the end number.
- for is for “this many times”. while is for “until something changes”.
Loading the playable lesson…