Swift正确断开多层交换机

时间:2016-09-07 15:53:46

标签: swift

我正在将代码从java重写为swift,需要正确地打破多层交换机。在Java中看起来像:

 block0 : switch (topSwithch) {
    case one: {
        switch (innerSwitch) {
        case insideCase: {
             if (something){
                break block0;
            }
// etc

所以,我打破了另一个开关。我怎么在swift中做到这一点?

1 个答案:

答案 0 :(得分:2)

这就是Swift的样子。我在一个操场上做了这个,其中包含变量的硬编码值:

let topSwitch = 1
let innerSwitch = 4
let one = 1
let insideCase = 4
let something = true

block0 : switch (topSwitch) { //first switch labeled "block0", switching on topSwitch
    case one: //topSwitch is 1, one is 1
        switch (innerSwitch) { // switching on innerSwitch
            case insideCase: // both are 1
                if (something){ // if true
                    break block0; // break from "block0"
                }
            default: break // else
        }
    default: break // else
}