Loops & Iteration
Djazair supports while, do-while, and rich for-in iterators across arrays, maps, strings, and ranges.
While & Do-While
djazair
# While loop
let count = 0
while count < 3
print("Count: ${count}")
count++
end
# Do-While loop (guarantees at least one execution)
let n = 0
do
print("Executed at least once, n = ${n}")
n++
while (n < 2)
For-in on Collections & Ranges
djazair
# 1. Iterating over an Array
let items = ["Alpha", "Beta", "Gamma"]
for item in items
print(item)
end
# 2. Iterating over an Integer Range (inclusive 0..4)
for i in 0..4
print("Index: ${i}")
end
# 3. Iterating over a String (character by character)
for char in "Djazair"
print(char)
end
# 4. Iterating over a Map with Key & Value
let capitals = {"Algeria": "Algiers", "Tunisia": "Tunis"}
for country, capital in capitals
print("The capital of ${country} is ${capital}")
end
Break & Continue
djazair
for i in 1..10
if i == 3
continue # Skip 3
end
if i == 6
break # Terminate loop at 6
end
print(i) # Prints 1, 2, 4, 5
end