Functions. Flow. Focus.
Build reusable functions and control how your program runs.
Functions with explicit signatures.
func Add(a: int, b: int) -> int
{
return a + b;
}
func Greet(name: string) -> void
{
CHUD.Print(name);
}Parameters are immutable. Argument types and counts must match. Function declarations are collected before bodies, allowing forward calls and recursion. Overloading is not implemented.
The entry point.
Executable projects require one public func Main() -> int with no parameters. Its return value is the exit status. Non-void functions must return on all paths the frontend recognizes. Loops are conservatively treated as able to finish.
Concise top-level programs are also supported. Their statements form an implicit Main that returns zero at the end. Do not combine top-level statements with an explicit Main in the same project.
Conditions stay boolean.
let speed = 10;
if speed > 5
{
CHUD.Print("Fast");
}
else
{
CHUD.Print("Slow");
}Conditions require bool. Parentheses are optional. else if is supported.
A few ways to repeat.
for number in 0..10
{
if number == 4 { continue; }
CHUD.Print(number);
}
mut count = 0;
while count < 3 { count += 1; }
loop { break; }Ranges are ascending and upper-exclusive: 0..10 yields zero through nine. Bounds are evaluated once. A start at or above the end produces no iterations. The iteration binding is immutable. break exits the innermost loop; continue advances or retests it.