![]() | Chapter 11: Phrases | ![]() ![]() |
11.10. Repeat running through |
Inform is not used very much for numerical work, so the kind of repeat loop described in the previous section is not much used. Inform's natural domain is really the world of things and rooms, so the following kind of repeat is much more useful.
repeat with item running through open containers:
...
Once again we create a new variable, "item", of only temporary validity. This time the phrases are repeated once for each open container presently found in the world. (If there are no containers, or they are all closed, the phrases will not be followed at all.)
As with counting the "number of ..." objects satisfying some property, we can run through a wide variety of possibilities - any description whose range is possible for Inform to search. For example:
repeat with dinner guest running through the people in the Dining Room:
...
repeat with possession running through things carried:
...
repeat with event running through non-recurring scenes which are going on:
...
The following lists the whereabouts of all men in lighted rooms:
repeat with suspect running through the men who are in a lighted room (called the scene):
say "[The suspect] is in [the scene].";
Note the way we are allowed to give a name to the vaguely described place "lighted room", so that we can refer to it inside the loop. This wasn't really necessary ("holder of the suspect" would have had the same effect) but improved the clarity of the source.
Once again, we are not allowed this:
repeat with N running through even numbers:
...
because the search would be infinite. See the Kinds index for which kinds of value can be repeated through.
| ![]() ![]() People who select partners for dance lessons each turn. |
|
Previous | Contents | Next |