Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Infinite Loops, Break, Continue
-
You can make an infinite loop accidentally...
while (gallonsOfGas < 8) {
move(30);
gallonsOfGas--;
}
-
Or intentionally.
while (true) {
move(30);
gallonsOfGas--;
}
-
Just make sure you have a way out
-
break breaks out of the loop.
-
continue starts from the top of the loop.
while (true) {
move(30);
if (!move) {continue;)
gallonsOfGas--;
if (gallonsOfGas <= 0) {break;}
}
The Grand Loops Example


Created by: Brandan
Jones January 4, 2002