Skip to reading
BASIC Scripting

Repeat until something changes

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

THE BASIC LANGUAGE

A WHILE loop checks before it starts. A DO loop with a test at the bottom always gets one turn. Choose the form that matches the rule you mean.

Code example
FUNCTION Run()
    DIM turns = 0
    WHILE turns < 2
        turns += 1
    WEND
    DO
        turns += 1
    LOOP UNTIL turns >= 3
    RETURN turns
END FUNCTION

The WHILE runs at 0 and 1, stopping at 2. The DO body then adds one, and LOOP UNTIL tests the new value. The result is 3.

Source table from Repeat until something changes, page 13
WHILE … WENDUse it when the body might need zero turns.
DO WHILE / DO UNTILPut the test at the top for another pre-tested form. Close with LOOP.
REPEAT … END REPEATGive a fixed number of repetitions. BREAK exits a loop. CONTINUE skips ahead to its next turn.

Change the value your loop tests. A tight loop waiting for a person to click cannot process the click. Use a GUI event or WAIT UNTIL for something that can change on a later frame.

Page 13 of 86Permalink
Go to page