You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letfirstCard=11letsecondCard=10
if firstCard + secondCard ==21{print("Blackjack!")}else{print("Regular cards")}
if firstCard + secondCard ==2{print("Aces - lucky!")}else if firstCard + secondCard ==21{print("Blackjack!")}else{print("Regular cards")}
Combining conditions
조건1 && 조건2 : 조건1과 조건2를 모두 만족해야 true
조건1 || 조건2 : 조건1 또는 조건2 하나가 true이면 true
letage1=12letage2=21
if age1 >18 && age2 >18{print("Both are over 18")}
if age1 >18 || age2 >18{print("One of them is over 18")}
The ternary operator
letfirstCard1=11letsecondCard1=10print(firstCard1 == secondCard1 ?"Cards are the same" : "Cards are different")
if firstCard1 == secondCard1 {print("Cards are the same")}else{print("Cards are different")}
Switch statements
switch
fallthrough : 조건에 맞는 case문 이후 모두 수행
letweather="sunny"
switch weather {case"rain":print("Bring an umbrella")case"snow":print("Wrap up warm")case"sunny":print("Wear sunscreen")fallthroughdefault:print("Enjoy your day!")}
Range operators
1..<5 ---> 1, 2, 3, 4
1...5 ---> 1, 2, 3, 4, 5
letscore4=85
switch score4 {case0..<50:print("You failed badly.")case50..<85:print("You did OK.")default:print("You did great!")}