Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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*/ ) {
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top