Summary: Repetition Continued

This lesson summarizes the main concepts presented in this chapter.

  • In a for loop, the process step forms the body. The initialization, test, and update steps are included explicitly right after the reserved word for.
  • A for loop has exactly the same logic as a while loop. We typically use a for statement for counted loops.
  • A for statement tests its condition immediately after any initialization occurs. Thus, the body of the loop might not execute at all.
  • We can omit either the initialization or the update step or both in a for statement, but we must retain the two semicolons.
  • When we declare two or more variables within a for statement, the variables must have the same data type. If they do not, we declare them before the for statement.
  • The do statement executes its body, which includes the update step, before evaluating a Boolean expression to decide whether to continue the iteration.
  • We must write a semicolon at the end of a do statement.
  • Use a do statement when we know that the body of the loop will execute at least once.

Get hands-on with 1200+ tech skills courses.