-
-
Notifications
You must be signed in to change notification settings - Fork 9
Unless Statement
IsaacShelton edited this page Mar 21, 2022
·
1 revision
Unless statements are used to conditionally execute a block of code
unless condition {
// ...
}
unless(condition){
// ...
}
unless condition, // ...
unless condition // ...
unless(condition) // ...
unless(condition), // ...
If the condition is false
, then the code inside the block will be executed
If the condition is true
, then other code can be executed instead by specifying an else
block
else {
// ...
}
} else {
// ...
}
else // ...
unless
is the negated version of the if
statement
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")
}
}