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, thedo-while
statement, and thefor
statement.Both the
while
statement and thedo-while
statement repeat the body of the loop while a boolean expression is true. Thedo-while
statement executes its body at least once, but thewhile
statement might not execute its body at all.The logic of a
for
statement is identical to that of awhile
loop. Its initialization, test, and update steps are given together, rather than dispersed throughout the loop. Thefor
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.