Blitz3D+ Command Reference

Repeat

Parameters

None.

Description

Starts a loop that always runs at least once.

Repeat opens the block and either Until or Forever closes it. The test lives at the bottom, so the body has always run once by the time anything is checked - the opposite of While, which can skip the body entirely.

That makes it the natural shape for anything you must do before you can judge the result: show a menu and then see what was picked, roll a random spawn point and then check it is clear, read a line and then test for the end of the file.

Repeat ... Forever is the other common form, used for a main loop whose exit is somewhere in the middle:

Repeat
    UpdateGame()
    If KeyHit(1) Then Exit
    Flip
Forever

Exit leaves the loop from anywhere inside it, which is often tidier than bending the Until condition to cover every case.

See also: Until, Forever, Exit, While, For.

Example

; Repeat Example
; --------------

; Vary the dice rolls on every run
SeedRnd MilliSecs()

; Repeat always runs its block at least once - Until tests afterwards
turns=0
Repeat
    turns=turns+1
    roll=Rand(1,6)
    Print "Turn "+turns+": you rolled a "+roll
Until roll=6

Print ""
Print "A six! You escaped the dungeon after "+turns+" turns."

Print ""
Print "Press any key to close the example"
WaitKey

End

Index