AKD
AKD

Reputation: 3964

javascript: goto statement

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

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 ?

Upvotes: 0

Views: 20515

Answers (3)

Andreas Louv
Andreas Louv

Reputation: 47127

Pretty sure you want to use continue;:

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

Upvotes: 4

Soner G&#246;n&#252;l
Soner G&#246;n&#252;l

Reputation: 98868

Use continue statement in your code;

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

It is one of the Jump statements.

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

Upvotes: 1

Habib
Habib

Reputation: 223422

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

Use continue statement instead of goto

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

Upvotes: 4

Related Questions