For 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.

  • DOS: Ctrl+C should work. If not, try Ctrl+Alt+Delete to reboot the computer.
  • Windows: Ctrl+Alt+Del gives you a chance to end a task that is not responding.
  • UNIX: You need to kill the process. Ask the local UNIX guru for details before writing a program with a 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: