![]() | Chapter 11: Phrases | ![]() ![]() |
11.11. Next and break |
Inside "repeat" and "while" loops, the new phrases "next" and "break" can be used to go directly to the next iteration, and to exit the loop immediately, respectively. ("Next" is called "continue" in a fair number of programming languages, so Inform issues a specific problem message to help people who forget this.) In Monopoly terms, "next" is "Advance to Go" rather than "go directly, do not pass Go, do not collect $200" - the next iteration begins with the variable, if there is one, having cleanly moved on to the next value, just as if the loop had been run through in the normal way.
For instance:
repeat with X running from 1 to 10:
if X is 4, next;
say "[X] ";
if X is 7, break;
prints the text "1 2 3 5 6 7", because the iteration when X is 4 is skipped over by the "next", whereas iterations 8, 9 and 10 never happen, since the "break" when X is 7 means they are never reached.
Previous | Contents | Next |