Skip to main content
added 13 characters in body
Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

This type of loops has 3 main parts

  1. initialization (e.g., N = 0)
  2. 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).
  3. 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

  1. evaluate the loop continuation condition
  2. if it evaluates to true, execute the body of the loop
  3. perform the update
  4. 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!

This type of loops has 3 main parts

  1. initialization (e.g., N = 0)
  2. the loop continuation condition — the code inside the body of the loop repeats as long as this condition evaluates to true (e.g., there is at least one more person in the room).
  3. 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

  1. evaluate the loop continuation condition
  2. if it evaluates to true, execute the body of the loop
  3. perform the update
  4. 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!

This type of loops has 3 main parts

  1. initialization (e.g., N = 0)
  2. the loop continuation condition — the code inside the body of the loop repeats as long as this condition evaluates to true (e.g., N is less than the number of persons in the room).
  3. 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

  1. evaluate the loop continuation condition
  2. if it evaluates to true, execute the body of the loop
  3. perform the update
  4. 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!

Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

This type of loops has 3 main parts

  1. initialization (e.g., N = 0)
  2. the loop continuation condition — the code inside the body of the loop repeats as long as this condition evaluates to true (e.g., there is at least one more person in the room).
  3. 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

  1. evaluate the loop continuation condition
  2. if it evaluates to true, execute the body of the loop
  3. perform the update
  4. 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!