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、匹配类型:还可以是字符串
  • 相关阅读:
    MemCached总结二:数据管理指令
    MemCached总结一:Unbutu操作系统下memcached服务器安装和telnet方式连接memcache
    Laravel5 开启Debug
    状压dp
    树形dp
    区间dp
    线性dp
    背包九讲
    dp求解各种子串子序列
    线段树详解
  • 原文地址:https://www.cnblogs.com/lignpeng/p/5458298.html
Copyright © 2011-2022 走看看