Skip to content

Control Flow

Control flow statements let your program make decisions and repeat actions.

If/Else

let x = 10
if (x > 5) {
    print("x is greater than 5")
} else {
    print("x is not greater than 5")
}

For Loops

let arr = [1, 2, 3]
for item in arr {
    print(item)
}

While Loops

let n = 3
while (n > 0) {
    print(n)
    n = n - 1
}

Next: Input and Output