Control flow

Counting with ranges

When you want to count rather than walk a collection, reach for a range. a..b is half-open: it starts at a and stops just before b. So 0..5 is the five numbers 0, 1, 2, 3, 4 — the 5 is left out.

That half-open shape is the same convention as Python’s range or Rust’s 0..5, and it’s what makes 0..n run exactly n times — no off-by-one to talk yourself through.