반응형
    
    
    
  
요약:
1. if, else if... 등으로 나타내야 하는 구문이 5개 이상이라면 무조건 switch 구문이 낫다.
2. if, else if.... = switch 같은 역할
위의 switch구문은 아래 if, else if 구문과 의미가 같다.

월 ~ 일요일 switch문으로 출력
(1 ~ 7에 해당하는 각각의 요일 출력)
////Don't change this
var aNumber =  Int(readLine()!)! 
func dayOfTheWeek(day: Int) {
  
  switch day {
      case 1:
      print("Monday")
      case 2:
      print("Tuesday")
      case 3:
      print("Wednesday")
      case 4:
      print("Thursday")
      case 5:
      print("Friday")
      case 6:
      print("Saturday")
      case 7:
      print("Sunday")
      default:
      print("Error")
  }
}


반응형
    
    
    
  'iOS > iOS Swift Udemy - AngelaYu' 카테고리의 다른 글
| 디버깅 5단계 (0) | 2022.10.24 | 
|---|---|
| iOS swift Int, Float 계산 순서 (0) | 2022.10.24 | 
| iOS swift Eggtimer - timer, progress bar (0) | 2022.10.23 | 
| dictionary practice (0) | 2022.10.22 | 
| Section 8: EggTimer / UIButton currentTitle 출력 (0) | 2022.10.20 |