-
-
Notifications
You must be signed in to change notification settings - Fork 9
Ternary Operator
IsaacShelton edited this page Mar 21, 2022
·
1 revision
The ternary operator can be used to evaluate different values based on a condition.
condition ? value1 : value2
- The condition must be convertible to
bool
- The first and second value must be of similar types
Only one of the two possible values will be evaluated. If the condition is true, the first will be, otherwise the second will be. Never will both be.
import basics
func main {
name String = scan("Enter your name: ")
print(name == "Isaac" ? "Welcome!" : "Hi there " + name + "!")
}