Control Flow
Larz covers how Larzscript makes decisions and repeats work: if/else and its mirror unless, while loops that check before every pass, and for loops that walk a list one item at a time.
if / else
A condition, no parentheses, then a block in braces. else is optional:
wallet player = $12.00
price entry = $5.00
if player.balance >= entry {
print("You're in!")
} else {
print("Top up first.")
}You're in!
unless
The mirror image of if - its block runs only when the condition is false. Reads nicely as a guard clause:
let lives = 0
unless lives > 0 {
print("Game over.")
}Game over.
while loops
Repeats its block for as long as the condition stays true. It checks again before every pass โ nothing more to it:
let lives = 3
while lives > 0 {
print(f"lives left: {lives}")
lives = lives - 1
}lives left: 3 lives left: 2 lives left: 1
for loops
Walks a list one item at a time with in. Pair it with an if to act on just the items you care about:
let scores = [10, 25, 40]
for s in scores {
if s >= 30 {
print(f"{s} -> high score!")
}
}40 -> high score!
Every snippet on this page is run through the real larzscript interpreter, not hand-typed โ what you see in the Output blocks is the actual output, for all four constructs: if/else, unless, while, and for.