طالما
Translation status: العربية reader-locale proof. Term names and code fences follow the ar pack; supporting prose may still be English.
Repeats a block while a condition remains true.
Aliases: while
Syntax: طالما <condition> <block|إذن statement>
Category#
control-flow
Related#
Examples#
radix/corpus/dum/dum.fab (canonical · keyword)#
Repeats a block while a condition remains true.
test "dum counts up to its condition" {
var int computus ← 0
while computus ≺ 5 {
computus ← computus + 1
}
assert computus ≡ 5
}
test "dum counts down to zero" {
var int reliquum ← 3
while reliquum ≻ 0 {
reliquum ← reliquum - 1
}
assert reliquum ≡ 0
}
# =============================================================================
# طالما — Repeats a block while a condition remains true.
# =============================================================================
#
# What this teaches:
# • While loop — `طالما <condition> { <body> }` repeats a block as long as the condition is true.
# • Loop variable mutation — mutable `متغير` bindings allow counter-based loop control.
# • Ascending and descending loops — counting up from 0 or down from N until the condition is خطأ.
#
# Common mistakes:
# • Using `اكسر` or `تابع` outside a loop — `تابع` needs an enclosing loop (`طالما`, `كرر`, `افعل … طالما`) in the same function (SEM031); `اكسر` also accepts a plain `افعل` block (SEM030).
#
# See also: إذا, إذن, افعل
# =============================================================================
# طالما — while loop
#
# طالما <condition> { <body> }
#
# GRAMMAR:
# loopStmt :← 'طالما' expr '{' stmt* '}'
#
# EXPECTED OUTPUT:
# dum.expected
main {
# Ascending counter: متغير so the loop variable can mutate
var int computus ← 0
while computus ≺ 5 {
print computus
computus ← computus + 1
}
# Descending loop: condition becomes خطأ at 0
var int reliquum ← 3
while reliquum ≻ 0 {
print "reliquum: §"(reliquum)
reliquum ← reliquum - 1
}
print "perfectum!"
}Expected output:
0
1
2
3
4
reliquum: 3
reliquum: 2
reliquum: 1
perfectum!