转载

How to break outer loops from inner structures that respond break (loops/switch)


问题:

How to I break an outer loop from within an nested structure that responds to the break statement in Swift?如何从响应 Swift 中的break语句的嵌套结构中中断外部循环?

For example:例如:

while someCondition {
    if someOtherCondition {
        switch (someValue) {
            case 0:     // do something
            case 1:     // exit loop
            case 2...5: // do something else
            default:    break
        }
    } else {
        someCondition = false
    }
}

The break will only get me out of the switch , and in Swift, it has to be used as empty cases are not allowed. break只会让我退出switch ,在 Swift 中,必须使用它,因为不允许使用空情况。 How can I entirely exit the loop from within the switch ?我怎样才能从switch内完全退出循环?

解决方案:

参考: https://stackoom.com/en/question/1cuPF
{{o.name}}
{{m.name}}
  • 转载自:https://my.oschina.net/u/3797416/blog/5393814
  • 留言