Swift
[Day 5] 조건문 : if, switch, and the ternary operator
쨈미니
2023. 8. 4. 00:22
1️⃣ if
if someCondition {
print("Do something")
} else if someCondition {
print("Do something")
} else {
print("Do something")
}
2️⃣ switch
enum Weather {
case sun, rain, wind, snow, unknown
}
let forecast = Weather.sun
switch forecast {
case .sun:
print("It should be a nice day.")
case .rain:
print("Pack an umbrella.")
case .wind:
print("Wear something warm")
case .snow:
print("School is cancelled.")
case .unknown:
print("Our forecast generator is broken!")
}
3️⃣ ternary conditional operator ( 삼항조건연산자 )
let hour = 23
print(hour < 12 ? "It's before noon" : "It's after noon")
// Some condition ? True : False