Chapter Summary

  • A loop is a programming construct that repeats an action some number of times. The part that is repeated is called the body of the loop. Every repetition of the loop body is called a loop iteration.

  • Java has three kinds of loop statements: the while statement, the do-while statement, and the for statement.

  • Both the while statement and the do-while statement repeat the body of the loop while a boolean expression is true. The do-while statement executes its body at least once, but the while statement might not execute its body at all.

  • The logic of a for statement is identical to that of a while loop. Its initialization, test, and update steps are given together, rather than dispersed throughout the loop. The for statement often ...

Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.