This type of loops has 3 main parts
- initialization (e.g., N = 0)
- the loop continuation condition — the code inside the body of the loop repeats as long as this condition evaluates to true (e.g., thereN is at least one more personless than the number of persons in the room).
- the update — eventually causes the loop continuation condition to evaluate to false so that we don't become stuck into an infinite loop (that runs forever because the condition never becomes false). For example, N = N + 1 (i.e., increment N by 1).
The initialization step happens only once at the very first iteration (repetition) of the loop (it obviously doesn't make sense that every time the loop iterates, N is initialized with 0).
After the initialization, this is the order of the steps that a loop uses
- evaluate the loop continuation condition
- if it evaluates to true, execute the body of the loop
- perform the update
- go back to 1
That said, if the loop continuation condition evaluates to false (even initially), the body of the loop never gets executed again and the first thing after the loop is executed.
Hope that helps!