Summary: Repetition

This lesson summarizes the major ideas we presented in this chapter.

  • A loop typically involves four steps: initialization, testing, processing, and updating.
  • A while statement tests its condition before executing the statements in its body. Thus, the body of the loop might not execute at all.
  • The operator ++ can be used to add 1 to a variable. Similarly, the operator -- can be used to subtract 1 from a variable.
  • When read, a sentinel value signals the end of a data set.
  • A common error in writing a loop causes the loop to cycle one too many or one too few times.
  • Another common error in writing a loop causes the loop to cycle endlessly.
  • We can use a Boolean variable in the condition of a while statement to indicate when the repetition should end.
  • When one loop is nested inside of another, the inner loop executes completely during each cycle of the outer loop.

Get hands-on with 1200+ tech skills courses.