Skip to content

Control Flow (if, for, while)

Nubo supports common control flow constructs to manage the flow of your programs.

if condition {
// code when true
} else {
// code when false
}

Example:

let age = 20
if age >= 18 {
println("Adult")
} else {
println("Minor")
}

Iterate over ranges or collections.

for i in range(0, 5) {
println(i)
}
let fruits = ["apple", "banana", "cherry"]
for fruit in fruits {
println(fruit)
}

Loop while condition is true:

let count = 0
while count < 3 {
println(count)
count = count + 1
}