Forge

Control Flow

Forge provides standard control flow constructs with Python-like syntax.

If / Elif / Else

if condition:
    # block
elif other_condition:
    # block
else:
    # block
let x = 10
if x > 0:
    puts("positive")
elif x < 0:
    puts("negative")
else:
    puts("zero")

While Loop

while condition:
    # body
var i = 0
while i < 10:
    if i == 5:
        break
    puts("iteration")
    i = i + 1

There is no while ... else.

For Loop

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 / Break / Continue

loop:
    # infinite loop
    if condition:
        break
    if skip:
        continue
var i = 0
loop:
    i = i + 1
    if i == 3:
        continue
    if i > 5:
        break
    puts("iteration")

Match Expression

match expression:
    case 0: puts("zero")
    case 1: puts("one")
    case _: puts("other")
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

return value    # return with value
return          # void return (or end of function)

Unsafe Blocks

unsafe:
    *ptr = 42                # Raw pointer write
    let val = *ptr           # Raw pointer read
    p = p + 1                # Pointer arithmetic

Unsafe is required for:

Keep unsafe blocks minimal and document why they are safe.

Block Expressions

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
}
var result = {
    var inner = {
        var n = 3
        n + 1      # inner block's value
    }
    inner * 10     # outer block's value
}

Panic / Abort

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.