Write counting loops with for.

In this video:

  • for (start; condition; step) { ... } keeps everything that controls the loop in one line
  • start runs once, before the loop
  • condition is checked before every round, as in while
  • step runs at the end of every round, such as ++i
  • i++ gives the old value and then adds one; ++i adds one and gives the new value
  • In a for loop, continue still runs the step, unlike the counter at the end of a while loop