while

← Back to documentation


Description

Repeats execution while condition is true.

Syntax

while (condition) expression

Parameters

Return Value

Value of the last iteration, or void if never executed

Examples

Simple counter

i = 0
while (i < 5) {
    i = i + 1
}
print(i)
# Output: 5

Sum of numbers

sum = 0
i = 1
while (i <= 10) {
    sum = sum + i
    i = i + 1
}
print(sum)
# Output: 55

Array iteration

arr = [10, 20, 30, 40]
i = 0
while (i < length(arr)) {
    print(arr[i])
    i = i + 1
}
# Output:
# 10
# 20
# 30
# 40

Infinite loop (with break condition)

i = 0
while (1) {
    i = i + 1
    if (i >= 10) {
        i
    }
}
print(i)
# Output: 10

Notes


See Also


© 2026 elliktronic · Jaf Language