Skip to content

Control Flow

Zap supports regular conditional statements:

if age >= 18 {
println("adult");
} else {
println("minor");
}

else if chains are also supported.

Parentheses around the condition are optional:

var i: Int = 0;
while i < 10 {
i = i + 1;
}

This also works:

while (i < 10) {
i = i + 1;
}

Loop control is supported and covered by the compiler tests:

while true {
if shouldSkip {
continue;
}
if shouldStop {
break;
}
}

Conditional expressions use ?::

var status: String = score >= 50 ? "pass" : "fail";

The condition must be Bool, and both branches must be type-compatible.