• swift switch语句


    switch选择
    1)case多条件匹配:条件之间用逗号隔开
    用三个点表示范围:…,..<:表示不包含上边界
    var tand = 1

    switch tand{
        case 0:
            println(tand)
        case 2,3,5:
            println(tand)
        case 6...10:
            println(tand)
        default :
            println(tand)
    }
     
    2)数值绑定
     
    let point = (10,1)
    switch point{
    //和point结构相同的,用来匹配传进来的值
    case (let x , 0):
        println("x = (x)")
    case (0,let y):
        println("y = (y)")
    case (let x,let y):
        println("x = (x) y = (y)")
    }
     
    3)匹配元组
    case (0 , 0):
    case (_ , 0):  //忽略第一个元素
     
     
    4)使用where来增加判断条件
     
    5)fallthrough:执行完当前case,继续向下执行
    注意:fallthrough后面的case条件不能定义变量和常量
    switch point{
    case (0...3, 6...10):
        println("(point)")
    case let ( x , y ) where x == y :
        println("(point)")
        fallthrough
    default:
        println("0")
    }
    输出结果:
    (5, 5)
    0
     
    注意:
    1、每一个case后面必须有一个可以执行的语句
    2、匹配类型:还可以是字符串
  • 相关阅读:
    scrapy爬虫爬取小姐姐图片(不羞涩)
    scrapy爬虫登录edusrc查看漏洞列表
    代码审计【根据功能点定向审计】BugFree ZSWin重装案例
    645-2007协议解析
    最近总结
    防爆zigbee模块
    物联网卡余额管理软件更新
    激光+紫外催化控制器
    modbus转edp协议
    modbus转mqtt工具
  • 原文地址:https://www.cnblogs.com/lignpeng/p/5458298.html
Copyright © 2020-2023  润新知