Game Development Reference
In-Depth Information
coded invinciBagelY = invinciBagelY + 1;
}
In contrast, the while (or do-while) type of loop does not execute over a finite num-
ber of processing cycles, but rather executes the statements inside the loop until a con-
dition is met, using the following structure:
while (boolean expression) {
programming statement one;
programming statement two;
}
To code the for loop to move the InvinciBagel 40 pixels, using a while loop struc-
ture, looks like this:
int x = 0;
while (x < 40) {
invinciBagelX++;
invinciBagelY++;
x++
}
The only difference between a do-while loop and a while loop is that, with the lat-
ter, the loop logic programming statements are performed before , instead of after, the
evaluation. Thus, using a do-while loop programming structure, the previous example
would be written as follows:
int x = 0;
do {
invinciBagelX++;
invinciBagelY++;
x++
} while (x < 40);
As you can see, the Java programming logic structure is inside curly braces, follow-
ing the Java do keyword, with the while statement after the closing brace. Note that
the while evaluation statement (and therefore the entire construct) must be terminated
with a semicolon .
Search WWH ::




Custom Search