AutolangDocs

Control flow

Autolang supports traditional control flow structures but elevates them by treating structures like if and when as expressions that return values.

If as an Expression

Similar to Kotlin, if and else can be used as expressions. This means they return a value, which allows you to assign the result directly to a variable. When used as an expression, an else branch is mandatory.

func testIfExpression() { val a = if (true) 10 else 20 println(a) // Prints 10 val b = if (false) 10 else 20 println(b) // Prints 20 // You can also use blocks. The last expression in the block is returned. val c = if (a == 10) { println("A is 10!") 20 // This is the return value of the block } else { 100 } println(c) // Prints 20 } testIfExpression()