Control Flow
Conditionals, loops, and program flow statements.
Conditional Statements
Control program execution based on conditions using if,
elseif, and else.
Basic if/else
set age = 25
if (age >= 18) {
print("Adult")
}
if/elseif/else Chain
set score = 75
if (score >= 90) {
print("A")
} else {
if (score >= 80) {
print("B")
} else {
print("C")
}
}
Each branch is evaluated only if the previous condition is false. All branches are optional.
While Loops
Execute a block repeatedly while a condition is true:
Simple Counter
set counter = 0
while (counter < 5) {
print(counter)
set counter = counter + 1
}
Sum 1 to 10
set sum = 0
set i = 1
while (i <= 10) {
set sum = sum + i
set i = i + 1
}
print(sum)
The loop repeats until the condition becomes false. Ensure your condition will eventually be false to avoid infinite loops.
for-in Loops
Iterate over arrays with for item in array,
or over object keys with for key, value in object.
Array Iteration
set items = [10, 20, 30]
for item in items {
print(item)
}
Object Iteration
set user = { name: "Kria", age: 5 }
for key, value in user {
print(key)
print(value)
}
Arrays use single iteration variable; objects use two (key and value). The loop processes each element in order.
break & continue
Control loop execution with break (exit immediately)
and continue (skip to next iteration).
break Example
set i = 0
while (i <= 100) {
if (i >= 50) {
print(i)
break
}
set i = i + 1
}
continue Example
set nums = [1, 2, 3, 4, 5, 6]
for n in nums {
set remainder = n - ((n / 2) * 2)
if (remainder == 0) {
continue
}
print(n)
}
break exits the innermost loop.
continue jumps to the next iteration.