Swift4.0 學習筆記 第五節:switch

//
//  ViewController.swift
//  008-switch
//
//  Created by 莊壯勇 on 2018/1/3.
//  Copyright © 2018年 Personal. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        demo(num: "10")
    }

    /**
     1.switch 可以針對任意類型的值進行分支,不再侷限在整數
     2.switch 一般不需要break
     3.switch 如果要多值。使用','
     4.所有的分支至少需要一條指令
     */
    func demo(num: String) {
        switch num {
        case "10","9":
            print("優")
        case "8":
            break;
        default:
            print("一般")
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章