在Swift 2.2.1中替换C样式的for循环 [英] Replace c style for-loop in Swift 2.2.1

查看:83
本文介绍了在Swift 2.2.1中替换C样式的for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的应用程序中的循环:

This is the loop in my app:

for var i = column - 1; i >= 0 && burgers[i, row]?.burgerType == burgerType;
        i -= 1, horzLength += 1 {

}

在Swift 2.2.1中实现此循环的最佳方法是什么?

推荐答案

尝试一下:

var i = column - 1
while i >= 0 && burgers[i, row]?.burgerType == burgerType {
    i -= 1
    horzLength += 1
}

这种滥用for循环语法的确切原因是它在Swift 2.2中被弃用.即使for语法可用,这仍然比可憎的语法更清楚

This sort of abuse of the for loop syntax was the exact reason it was deprecated in Swift 2.2. Even if a for syntax was available, this would still be more clear than that abomination

这篇关于在Swift 2.2.1中替换C样式的for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆