Skip to content

Control Flow

Conditional statements

Conditional statements are used to execute code based on a condition.
In Eiger, the if statement is used to execute code if a condition is true. The else statement is used to execute code if the condition is false. else statements are optional and go after if statements.

if statement

if true {
    emitln("condition is true")
}

if-else statement

if 1 + 1 ?= 2 {
    emitln("1 + 1 = 2")
} else {
    ~ Unreachable code
}

Loops

There are 2 types of loops. for and while.

for loops

In Eiger, for loops have 2 parts: Variable declaration and end value
Let's say we need to have a value x and it will increment by 1 until the end value, we also need to execute a block of code on each iteration
These types of loops are called Count-controlled loops

for x = 0 to 10 {
    emitln(x)
}

while loops

While loops will repeat the code until the given condition is not true anymore. Those are called Condition-controlled loops

x = 0
while x < 10 {
    emitln(x)
    x += 1
}