September 2011
Beginner
650 pages
15h 47m
English
In Java, the body associated with a for loop (or any other loop) can be empty. This is because a null statement is syntactically valid. Body-less loops are often useful. For example, the following program uses one to sum the numbers 1 through 5:

Notice that the summation process is handled entirely within the for statement, and no body is needed. Pay special attention to the iteration expression:
![]()
Don’t be intimidated by statements like this. They are common in professionally written Java programs and are easy to understand if ...
Read now
Unlock full access