Next: , Previous: , Up: Statements   [Index]


7.3 NEXT, FORGET and RESUME

INTERCAL-72 C-INTERCAL CLC-INTERCAL J-INTERCAL
yes all versions see text all versions

The only flow-control commands in INTERCAL-72 were NEXT, RESUME, and FORGET; together these manipulate a stack of locations in the program known as the ‘NEXT stack’. Although all INTERCAL compilers have implemented these, from CLC-INTERCAL version 0.05 onwards CLC-INTERCAL has considered them obsolete, and therefore a special command-line switch needs to be used to enable them. (They are still the most portable flow-control commands currently available, though, precisely because INTERCAL-72 implements nothing else.) Note that there is a strict limit of 80 locations on the NEXT stack, enforced by all known INTERCAL compilers; this helps to enforce good programming style, by discouraging NEXT-stack leaks (which are otherwise quite easy to write).

Here are examples to show the syntax of these three statements:

DO (1000) NEXT
DO FORGET '.1~.1'~#1
DO RESUME .5

The NEXT command takes a line label as its argument (unlike most other INTERCAL commands, it comes after its argument rather than before); both FORGET and RESUME take expressions. (CLC-INTERCAL from version 0.05 onwards also allows an expression in NEXT, rather than a label, to give a computed NEXT, but this behaviour was not implemented in other compilers, and is deprecated in CLC-INTERCAL along with noncomputed NEXT; if computed NEXT is ever implemented in C-INTERCAL, it will likely likewise be deprecated upon introduction). (Update: it was implemented in C-INTERCAL version 0.28, but only as part of the external calls system, so it cannot be used in ordinary programs; a sample expansion library gives in-program access to a limited form of computed NEXT, but should probably not be used.) Running a NEXT causes the program control to transfer to the command whose line label is referenced, and also saves the location in the program immediately after the NEXT command on the top of the NEXT stack.

In order to remove items from the NEXT stack, to prevent it filling up (which is what happens with a naive attempt to use the NEXT command as an equivalent to what some other languages call GOTO), it is possible to use the FORGET or RESUME commands. They each remove a number of items from the NEXT stack equal to their argument; RESUME also transfers control flow to the last location removed from the NEXT stack this way. Trying to remove no items, or more items than there are in the stack, does not cause an error when FORGET is used (no items or all the items are removed respectively); however, both of these cases are errors in a RESUME statement.

Traditionally, boolean values in INTERCAL programs have been stored using #1 and #2 as the two logic levels. This is because the easiest way to implement an if-like construct in INTERCAL-72 is by NEXTING, then NEXTING again, then RESUMING either by 1 or 2 according to an expression, and then if the expression evaluated to 1 FORGETTING the remaining NEXT stack entry. By the way, the previous sentence also explained what the appropriate gerunds are for NEXT, RESUME, and FORGET.


Next: , Previous: , Up: Statements   [Index]