Control Flow keyword

guard

Swift-style early exit when a condition is false.

guard condition else { ... } inverts the condition and requires the else block to exit (return, throw, break, or continue). Useful for flattening nested if chains.

Affogato

example.aff
describe(value: Object): String {
    guard value is String else {
        return "other"
    }
    return value as String
}

Generated Java

Example.java
public String describe(Object value) {
    if (!(value instanceof String)) {
        return "other";
    }
    return ((String) value);
}

Related

See also

← All keywords