Welcome to the Creatures Wiki! Log in and join the community.


From Creatures Wiki
Jump to navigation Jump to search

LOOP is a CAOS command controlling flow.


LOOP marks the start of a block of code which is to be looped unboundedly. There are two types of unbounded loop in CAOS: LOOP..EVER and LOOP..UNTL.


Syntax: LOOP .. EVER

LOOP..EVER just repeats the same block of code over and over, until a STOP instruction is reached, or the script is interrupted (if running SLOW).


Syntax: LOOP .. UNTL cond (condition)

LOOP..UNTL repeats the loop block, but at the end of each iteration cond is evaluated and if it is found to be true, the loop is terminated. STOP and interruptions still break out of the loop, as above.

This is a do { ... } until (cond) loop in many programming languages. To simulate a while loop, you can wrap the whole thing in a DOIF.

Do not attempt to break out of any loop using a GOTO or RETN command! It will crash your script. STOP is the only valid instruction for breaking a loop.


This uses LOOP..UNTL to almost-replicate an ENUM loop, outputting UNIDs as it goes:

SETA va00 NCLS NULL 0 0 0
TARG va00
  OUTS "\n"
UNTL TARG eq va00

LOOP..EVER can be used, and is in the Bootstrap, to continue doing something until a script interrupts.

LOOP being used for a critter to walk towards a chosen leaf UNTL either it touches the leaf OR the leaf ceases to exist

See also

External links