Forge provides standard control flow constructs with Python-like syntax.
if condition:
# block
elif other_condition:
# block
else:
# block
boolelif and else are optionalif is a statement, not an expression (no let x = if ...)let x = 10
if x > 0:
puts("positive")
elif x < 0:
puts("negative")
else:
puts("zero")
while condition:
# body
boolbreak and continue work insidevar i = 0
while i < 10:
if i == 5:
break
puts("iteration")
i = i + 1
There is no while ... else.
for i in 0..10: # start..end: exclusive end (0..9)
puts(i)
for i in 0..=10: # inclusive end (0..10)
puts(i)
The range endpoints are integer expressions. Iterating over arrays
(for x in arr) is not supported yet — index with a range instead.
loop:
# infinite loop
if condition:
break
if skip:
continue
break exits the innermost loopcontinue skips to the next iterationwhile, for, and loopvar i = 0
loop:
i = i + 1
if i == 3:
continue
if i > 5:
break
puts("iteration")
match expression:
case 0: puts("zero")
case 1: puts("one")
case _: puts("other")
_ is the wildcard (catch-all)match c:
case 'a': puts("letter a")
case 'b': puts("letter b")
case _: puts("other")
Enum variant patterns are supported: case Color.Red: matches a unit variant,
and case Option.Some(x): destructures a payload variant, binding x. Variable
bindings outside of enum payloads, guards, and struct patterns are not supported
yet.
return value # return with value
return # void return (or end of function)
loop/while/for, returns from the enclosing functionreturnunsafe:
*ptr = 42 # Raw pointer write
let val = *ptr # Raw pointer read
p = p + 1 # Pointer arithmetic
Unsafe is required for:
*p)p + n, p - q)Keep unsafe blocks minimal and document why they are safe.
Braces can also be used as an expression that evaluates to the value of its trailing statement:
var x: int32 = {
var a = 6
var b = 7
a * b # trailing expression — this is the block's value
}
let/var bindings, if/while/for, match, and
returnreturn, let), the block’s
value is voidunsafe blocks work the same way as expressions: puts(unsafe { ... })var result = {
var inner = {
var n = 3
n + 1 # inner block's value
}
inner * 10 # outer block's value
}
from std.runtime import abort
from std.io import exit
abort() # Immediate termination (SIGABRT)
exit(1) # Clean exit with code
There is no unwinding — abort terminates immediately.