I keep reading about endless loops, is that something you want or do you always have to control an endless loop situation?
Your operating system runs in an endless loop.
Truly endless loops are obviously bad news (i.e., shut off the computer and restart). However, most "endless loops" usually provide a way to break out. Here is a common and useful variety:
[php]
while True:
name = raw_input("What is your name? ")
if name == "King Arthur of Camelot":
break
[/php]
In this endless loop, the right response will get you over the bridge of death ... I mean, out of the loop.
This is called a "test-last" loop, because the test comes at the end of the loop. In many languages, it would be implemented as a "do ... until" type of construct. The point of test-lasting is to make sure that the body of the loop is executed at least once (i.e., the question gets asked at least once).
Others might implement the same code as
[php]
name = ""
while name != "King Arthur of Camelot":
name = raw_input("What is your name? ")
[/php]
but I like the first version.
Here's another example: a shell
[php]
dir = "C:"
while True:
command = raw_input(dir + "> ")
if command.startswith("dir"):
list_dir(command[3:]) # this would be parsed differently in real life!
elif command.startswith("cd"):
dir = change_dir(command[2:])
elif command == "exit":
break
else:
print "command not found"
[/php]
This shell format is the basis for text games, command-line interpreters, etc.
Jeff