Skip to content

guard

Control flow

If the condition is false, the else block runs (usually return). Early-out, not an if replacement.

guard (condition) else {
warn("…");
return;
}
NameTypeDescription
conditionboolMust be true to continue.

None. The else block typically returns.

if not (condition) then … end

The else is required. After a successful guard, the compiler (and the reader) treat the condition as established — e.g. player != null.

guard (player != null) else {
warn("Invalid player");
return;
}
post(player.Name);

Emits:

if not (player ~= nil) then
warn("Invalid player")
return
end
print(player.Name)

if · null · match