Swift控制流

17 篇文章 0 订阅

let base = 3
let pow = 10
var answer = 1
for _ in 1…pow{

answer *= base

}

for index in 0 ..< 3 {

}

let test = “c”

switch test{
case “a”: print(“(test) is equ to a” )
case “b”,”c”,”d”:print(“是bcd 中的其中一个”) //支持多个匹配

case “b”: print(“(test) is equ to b”)
default :print(“not found”)
}

//repeat {// 类 oc 中 do while
// print(“a”)
//
//
//}while 2 > 0// 为真执行输出 , 为假退出循环.

let somePoint = (1, 1)
switch somePoint {
case (0, 0):
print(“(0, 0) is at the origin”)
case (_, 0):// x值不论
print(“((somePoint.0), 0) is on the x-axis”)
case (0, _):// y值不论
print(“(0, (somePoint.1)) is on the y-axis”)
case (-2…2, -2…2):
print(“((somePoint.0), (somePoint.1)) is inside the box”)
default:
print(“((somePoint.0), (somePoint.1)) is outside of the box”)
}
// prints “(1, 1) is inside the box”

let anotherPoint = (2, 0) //元组
switch anotherPoint {
case (let x, 0):
print(“on the x-axis with an x value of (x)”) //在 x轴上
case (0, let y):
print(“on the y-axis with a y value of (y)”) //在 y轴上
case let (x, y):
print(“somewhere else at ((x), (y))”) //在 象限内.
}
// prints “on the x-axis with an x value of 2

//continue 如果为真 直接跳过这次循环。 进入下次循环。。.

// break 跳出整个循环 循环终止.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值