| Chapter 11: Phrases |

| 11.6. While

The other main control phrase is "while", which has the form:

> while (... condition ...) repeatedly (... another whole phrase ...)

which keeps on applying the same phrase as long as the condition holds. If it never holds, even at the start, then the phrase is never applied at all and nothing happens. Just as the word "then" in an "if" can be abbreviated with a comma, so can the word "repeatedly" here.

We must be careful not to commit mistakes like the following:

> while eggs is eggs repeatedly say "again and "

which, as sure as eggs is eggs (which is very sure indeed), writes out

> again and again and again and again and again and ...

forever. (Inform won't prevent this: we will find out the hard way when the game is played.) While we would probably never write anything so blatant as that, the mistake is all too easy to commit in disguised form. We should never design a loop, as repetitions like this are called, without worrying about if and when it will finish.

Previous | Contents | Next