javascript:goto 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14335353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:20:41  来源:igfitidea点击:

javascript: goto statement

javascript

提问by Ashok Damani

I have a for loop, but in one condition, I want to skip some steps so that I have used gotostatement...

我有一个 for 循环,但在一种情况下,我想跳过一些步骤,以便我使用goto语句...

for (var rows = 0; rows < result.data.length; rows++) {
  [lbl] topOfLoop:

  var row = result.data[rows]
  if (row[0] == "") {
    goto topOfLoop;
  }

  ----- // some code
}

Its not working ? Can anyone tell me, how it could be done ?

它不工作?谁能告诉我,怎么做?

回答by Habib

i want to skip some steps so that i'v used goto statement...

我想跳过一些步骤,以便我使用 goto 语句...

Use continuestatement instead of goto

使用continue语句而不是 goto

for (var rows = 0; rows < result.data.length; rows++) 
    {
        var row = result.data[rows]
        if (row[0] == "") 
        {
           continue;
        }

回答by andlrc

Pretty sure you want to use continue;:

很确定你想使用continue;

for (var rows = 0; rows < result.data.length; rows++)  {
    var row = result.data[rows];
    if (row[0] == "") {
        continue;  
    }
    // some code
}

回答by Soner G?nül

Use continuestatement in your code;

continue在你的代码中使用语句;

The continue statement passes control to the next iteration of the enclosing iteration statement in which it appears.

continue 语句将控制传递给它出现的封闭迭代语句的下一次迭代。

It is one of the Jump statements.

它是 Jump 语句之一。

if (row[0] == "")
{
     continue;  
}