Next: , Previous: Conditionals, Up: Language


2.9 Loops

There are several ways to loop pieces of code in Enigma. One can create a function that calls itself, for example. It is, however, advised to use the loop function.

# Infinite loop
{stdout "Forever\n" ! write; true = return;} ! loop;
loop works a bit like act, except that it runs on the premise of the return value of the function it calls. If it returns true, or any other value that can be considered true (non-zero numbers, non-empty strings, files, etc.), it runs the function again. If it returns false, the loop stops. It naturally runs the first time no matter what (no return value has been created yet).