来源:6-3 switch语句的高级用法

海河之家

2014-10-29 22:30

var coordinate = (1,1)
switch coordinate
{
case (0,0):
    println("It's at origin!")
case (1,0):
    println("It's an unit vector on the positive x-axis.")
case (-1,0):
    println("It's an unit vector on the negative x-axis.")
case (0,1):
    println("It's an unit vector on the positive y-axis.")
case (0,-1):
    println("It's an unit vector on the negative y-axis.")
default:
    println("It's just an ordinary coordinate.")
    
}

switch coordinate
{
case (0,0):
    println("It's at origin!")
case (_,0):
    println("(\(coordinate.0),0) is on the x-axis.")
case (0,_):
    println("(0,\(coordinate.0)) is on the y-axis.")
default:
    println("(\(coordinate.0),\(coordinate.1)) is just an ordinary coordinate.")
}


写回答 关注

0回答

还没有人回答问题,可以看看其他问题

玩儿转Swift

这套教程比任何的Swift中文教程深入,并且演示示例更丰富

57267 学习 · 512 问题

查看课程

相似问题

回答 3

回答 3

回答 2

回答 2

回答 1