The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall

Do...Until loop

From Unreal Wiki, The Unreal Engine Documentation Site
(Redirected from Do loop)
Jump to: navigation, search

The do...until loop is a loop construct similar to the while loop, but runs at least once.

Syntax[edit]

The syntax of the do...until loop is exactly what you would expect from its name:

do {
  ...
} until (condition);

Note that UnrealScript doesn't "do...while", that means it loops until the condition is True. (or while it is False)

Like in any other loop construct you can use break and continue to exit the loop or jump to the next iteration.

Quirks[edit]

In Unreal Engine 1 and 2 the compiler wasn't too strict when checking the until statement. You could omit it, essentially creating an infinite loop that had to be exited with the break or return statement. This "feature" was removed in Unreal Engine 3.

A variation of the do...until loop is available in all engine generations. Like with the other loop constructs, you can specify a single statement instead of the code block after the keyword do:

do
  statement;
until (condition);

Note that the statement needs to be terminated with a semicolon, similar to the non-block version of the If statement that requires a semicolon after its statement even if an else statement follows. It is strongly recommended to enclose even a single statement in curly braces to prevent potential misunderstandings and oversights.