打破一会儿循环,一口气切换

box*_*pah 3 javascript break while-loop switch-statement

关于C ++中的这个问题,存在类似的问题,但是我在这里使用JavaScript。我基本上和其他帖子中的OP处于相同的情况。

var input = prompt();
while(true) {
    switch(input) {
        case 'hi':
        break;
        case 'bye':
            //I want to break out of the switch and the loop here
        break;
    }
    /*Other code*/
}
Run Code Online (Sandbox Code Playgroud)

反正有这样做吗?

我/*Other code*/在代码也应该中断的部分中也有多个开关。

Cal*_*mmm 5

您可以在js中使用break语句使用标签

var input = prompt();

outside:
while(true) {
    switch(input) {
        case 'hi':
        break;
        case 'bye':
            //I want to break out of the switch and the loop here
        break outside;
    }
    /*Other code*/
}
Run Code Online (Sandbox Code Playgroud)