Conditions
Conditions control the flow of execution based on boolean expressions.
If Statement
Section titled “If Statement”The basic if block starts with if and ends with fin if.:
if @ready launch!fin if.If-Else
Section titled “If-Else”if @score >= 90 write("A")else write("Not A")fin if.If-Else If-Else Chain
Section titled “If-Else If-Else Chain”if @score >= 90 write("A")else if @score >= 80 write("B")else if @score >= 70 write("C")else if @score >= 60 write("D")else write("F")fin if.Condition Expressions
Section titled “Condition Expressions”Conditions must evaluate to Boolean:
@// Validif @activeif @count > 0if @name == "test"
@// Invalid (will not compile)if @count @// Error: expected Boolean, got IntComplex Conditions
Section titled “Complex Conditions”Combine conditions with and, or, not:
if @age >= 18 and @has_id write("Entry allowed")fin if.
if @status == "active" or @status == "pending" write("Processing")fin if.
if not @disabled write("Enabled")fin if.Nested Conditions
Section titled “Nested Conditions”if @authenticated if @admin write("Admin panel") else write("User panel") fin if.else write("Please log in")fin if.Pattern Matching with Match
Section titled “Pattern Matching with Match”For complex branching, use match:
match @status when "active" then write("Running") when "paused" then write("Paused") when "stopped" then write("Stopped") else write("Unknown status")fin match.Match with Types
Section titled “Match with Types”match @value when String then write("String: " + @value) when Int then write("Int: " + string(@value)) when Boolean then write("Boolean: " + string(@value)) else write("Unknown type")fin match.Match with Guards
Section titled “Match with Guards”match @score when @s if @s >= 90 then write("A") when @s if @s >= 80 then write("B") when @s if @s >= 70 then write("C") else write("F")fin match.Conditional Expressions
Section titled “Conditional Expressions”Use if as an expression:
@if @score >= 60 @result = "pass"else @result = "fail"fin if.
@// Or inline@result = if @score >= 60 then "pass" else "fail" fin if.Unless Statement
Section titled “Unless Statement”Inverse of if (executes when condition is false):
unless @authenticated redirect("/login")fin unless.Short-Circuit Evaluation
Section titled “Short-Circuit Evaluation”and and or short-circuit:
@// If @list is nil, @list#length is never calledif @list != nil and @list#length > 0 process(@list)fin if.Common Patterns
Section titled “Common Patterns”Early Return
Section titled “Early Return”action process(@data: String?) if @data == nil return fin if. @// Process data...fin action.Guard Clause
Section titled “Guard Clause”action divide(@a: Float, @b: Float) -> Float? if @b == 0.0 return none fin if. return some(@a / @b)fin action.Ternary-Like Expression
Section titled “Ternary-Like Expression”@label = if @active then "Active" else "Inactive" fin if.Next Steps
Section titled “Next Steps”Continue to Loops for iteration constructs.
