Skip to content

If Statement

IsaacShelton edited this page Mar 21, 2022 · 1 revision

If Statement

If statements are used to conditionally execute a block of code

if condition {
    // ...
}
if(condition){
    // ...
}
if condition,  // ...
if condition   // ...
if(condition)  // ...
if(condition), // ...

Execution Condition

If the condition is true, then the code inside the block will be executed

Else Clause

If the condition is false, then other code can be executed instead by specifying an else block

else {
    // ...
}
} else {
    // ...
}
else // ...
else if // ...
elif // ...

Usage example

import basics

func main {
    age int = scanInt("How old are you? ")
    
    if age >= 18 {
        print("You are an adult")
    } else {
        print("You are a child")
    }
}
Clone this wiki locally