Skip to content

Control Flow

Nubo includes straightforward control flow for branching and looping.

Use if to run code conditionally:

if x > 1 {
println("x is greater than 1")
}

Conditions usually use comparison operators such as ==.

Use for to repeat code.

When looping over an integer, Nubo iterates from 0 up to that number:

for i in 15 {
println(i)
}

This prints numbers starting from 0.

The loop variable is available inside the loop body:

let sum = 0
for i in 10_000 {
sum = sum + i
}
println("Sum:", sum)

Use break to exit a loop early:

fn x() void {
for i in 10 {
if i == 5 {
break
}
}
}
x()

Use nil to represent a missing value:

let value: string|nil = "Hello"
if isNil(value) {
println("No value")
}