Zebra0.com

java loopsEndless Loops

Endless Loops

Occasionally, a programmer writes a loop that never ends. In fact, it is really easy to write an endless loop. Before you start writing loops, it is a good idea to find out how to stop the program if it is in an endless loop.

If I count by 5's and want to stop when I get to 17, I will never stop, because I will say 5, 10, 15, 20, 25, etc. but I will not say "17".

Another example is if I am count 1, 2, 3, and tell the loop to stop when I get to 0.

NEXT: Ask how many numbers