Walrus/Language

Control Flow

Branching, loops, switch dispatch, short-circuit logic, and return flow in Walrus.

Updated April 13, 20262 min readWalrus / Control Flow

Walrus uses colon-delimited blocks for all control-flow forms.

Conditionals

Walrus
if x < 0:
    return 0 - x
return x

else is supported as an optional second block:

Walrus
if ready:
    return 1
else:
    return 0

Loops

The main loop form is while:

Walrus
let sum = 0
let i = 0

while i < 10:
    sum += i
    i += 1

Logical operators

Short-circuit && is available:

Walrus
if sum == 45 && values[1] == 12:
    return 1

Switch

Walrus also supports switch with case labels:

Walrus
switch team:
    case Team.Neutral:
        return 0
    case Team.Red:
        return 1
    default:
        return 0

Returns

Functions return a single value:

Walrus
return 1

Numeric for loops and iterator-driven control flow are still not part of the language yet.