< Previous | Contents | Next >
You can use empty statements in creating your for loop, as I did in the following loop:
for ( ; count < 10; )
I used an empty statement for the initialization and action statements. That’s fine because I declared and initialized count before the loop and incremented it inside the loop body. This loop displays the same sequence of integers as the very first loop in the program. Although the loop might look odd, it’s perfectly legal.
Hin t
Different game programmers have different traditions. In the last chapter, you saw that you can create a loop that continues until it reaches an exit statement—such as a break—using while (true). Well, some programmers prefer to create these kinds of loops using a for statement that begins for (;;). Because the test expression in this loop is the empty statement, the loop will continue until it encounters some exit statement.
86 Chapter 3 n For Loops, Strings, and Arrays: Word Jumble