zoukankan      html  css  js  c++  java
  • 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、匹配类型:还可以是字符串
  • 相关阅读:
    计算机网络(1)----概述
    博客园自定义样式
    linux进程
    接口回调解析
    优先级队列
    双栈实现队列
    递归解决反转链表的一部分
    Multisim 之逻辑转换仪
    Multisim 如何添加文本 如何编辑文本字体
    Multisim 中的一些快捷键
  • 原文地址:https://www.cnblogs.com/lignpeng/p/5458298.html
Copyright © 2011-2022 走看看