且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

标签如何与不是循环的语句一起使用?

更新时间:2023-09-19 11:01:22

显然,break和continue语句可以在任何语句中使用:

Apparently the break and continue statements can be used within any statement:

http://docstore.mik.ua/orelly/webprog/jscript/ch06_11.htm

在这种情况下,这样的事情变得合法:

In which case things like this become legal:

function show_alert()
{
    label:
    {
        break label;
        alert("Hello! I am an alert box!");
    }
    alert("hi");
}

调用show_alert()时,只显示hi警告。

When show_alert() is called, only the "hi" alert is shown.

据我所知,这是{}代码块的唯一用途,而不是代码样式。 (这里有一个问题,没有人可以提出除可读性以外的任何东西,但我现在找不到它......)

As far as I know, this is the only use of the {} code blocks, other than for code styling. (there was a question on here about that, and noone could come up with anything other than readability, but I can't find it now...)