Syntax
Runs its body once per frame: the frame loop of a classic game. Code before DO runs once first, code after LOOP runs once when EXIT leaves the loop.
[<statements>]
DO
<statements>
Sync()
LOOP
[<statements>]Also written : DO, LOOP
Parts
| <statements> | Before DO: setup, run once. Between DO and LOOP: the frame body. After LOOP: run once, after EXIT. |
|---|
Good to know
- One
DO … LOOPper program, at the top level only. Not inside an IF, a loop or a FUNCTION: "DO/LOOP is supported once, at top level only". - The body must call Sync(), Swap() or
YieldTask()to hand the frame back. Without it the compiler says "DO/LOOP requires SYNC() so the loop can yield a frame". - In AGK and DarkBASIC, DO … LOOP is a plain endless loop. Here it is the frame loop. For any other loop, use WHILE or REPEAT.
DO WHILE,DO UNTIL,LOOP WHILEandLOOP UNTILdo not exist. CONTINUEin the frame loop skips the Sync() below it. If it fires on every pass, the game freezes. Put Sync() before theCONTINUE.- Do not write a
FUNCTION main()in a program with a DO loop: the loop is compiled under that name, the two collide, and the loop never runs. Nothing warns you. ENDinside the loop stops the program and skips the code afterLOOP. Wait() and Sleep() are refused afterLOOP.
Example
frames = 0Console("start") ' startDO frames = frames + 1 IF frames = 3 THEN EXIT Sync()LOOPConsole("left after " + Str(frames)) ' left after 3In the manual : The game loop and tasks