Skip to content

Unless Statement

IsaacShelton edited this page Mar 21, 2022 · 1 revision

Unless Statement

Unless statements are used to conditionally execute a block of code

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

Execution Condition

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

Else Clause

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

else {
    // ...
}
} else {
    // ...
}
else // ...

If vs Unless

unless is the negated version of the if statement

Usage example

import basics

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