Infinite Loops, break, continue
-
You can make an infinite loop accidentally...
while (gallonsOfGas < 8) {
move(30);
gallonsOfGas--;
}
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;}
}
Built-In Objects
Home
Internet II: Day 2