-5

I have a short question: How can I move from A to B in this code:

for(var i=0;i<length;i++)
{
    B <--------------- So far
    if (/*condition*/)
    {                   
        if(/*condition*/)
        {                       
            .....
        }
        else {
            A  <------------ From here
        };
    }
    else if(/*condition*/)
    {
        ...
    }
}

I know about break and continue, but it doesn't work here

Thanks all!

bdukes
  • 152,002
  • 23
  • 148
  • 175
Adacho
  • 99
  • 4
  • 13

2 Answers2

0

Recursion

for(var i=0;i<length;i++) {
    someFunc(i);   
}

function someFunc(i){
    if (/*condition*/){                   
        if(/*condition*/) {     
        } else {
            return someFunc(i) //change i  to prevent infinite loop
        }
    } else if(/*condition*/ ) {
    }
}
kwarunek
  • 12,141
  • 4
  • 43
  • 48
0

You could probably use goto.js (http://summerofgoto.com/) to handle this with the exact loop that you're trying to use, but you should consider just finding a different way to factor your code.

CamHenlin
  • 194
  • 8
  • continue works in the OP's code. I don't know what OP is talking about. – djechlin Aug 07 '13 at 17:41
  • Yeah, it's a really oddly worded question. Thanks for the downvote :) – CamHenlin Aug 07 '13 at 17:43
  • 1
    Downvote is because I think it's a bad idea to give a really complex answer/suggestion when the OP clearly has a very basic misunderstanding going on. If someone doesn't know how to add two numbers, you don't recommend jQuery. – djechlin Aug 07 '13 at 17:49