c语言中的warn函数用法,#warning:不赞成使用C语言的for语句,并将在以后的Swift版本中删除...

删除for init; comparison; increment {}并删除++和--轻松。并使用Swift的漂亮for-in循环// WARNING: C-style for statement is deprecated and will be removed in a future version of Swift

for var i = 1; i <= 10; i += 1 {

print("I'm number \(i)")

}

Swift 2.2:// new swift style works well

for i in 1...10 {

print("I'm number \(i)")

}

递减指数for index in 10.stride(to: 0, by: -1) {

print(index)

}

或者你可以使用reverse()像for index in (0 ..

浮球型 (there is no need to define any types to index)for index in 0.stride(to: 0.6, by: 0.1) {

print(index)  //0.0 ,0.1, 0.2,0.3,0.4,0.5

}

Swift 3.0:

从开始Swift3.0,stride(to:by:)Strideable上的方法已替换为自由函数,stride(from:to:by:)for i in stride(from: 0, to: 10, by: 1){

print(i)}

对于中的递减索引Swift 3.0,您可以使用reversed()for i in (0 ..

print(i) // 4,3,2,1,0}

其他则for each和stride(),则可以使用While Loopsvar i = 0while i 

i += 1

print(i)}

Repeat-While Loop:var a = 0repeat {

a += 1

print(a)} while a 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值