4.1 Java Loop Statements

Each thing is of like form from everlasting and comes round again in its cycle.

—MARCUS AURELIUS, Bartlett’s Familiar Quotations (1919)

Programs often need to repeat some action. For example, a grading program would contain branching statements that assign a letter grade to a student on the basis of the student’s scores on assignments and exams. To assign grades to the entire class, the program would repeat this action for each student in the class. A portion of a program that repeats a statement or group of statements is called a loop. The statement or group of statements to be repeated in a loop is called the body of the loop. Each repetition of the loop body is called an iteration of the loop.

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.