loading...

re: JavaScript, stuff you've never heard of (probably): labeled loops? VIEW POST

FULL DISCUSSION
 

Hey, nice post.
I can't think when I'd use this. Usually if there are exit conditions I use a while loop. When would I use a named for loop and not a while loop containing a for loop - or merged together like this:

for (let i = 0; i < ar.length && !extrenousCondition; i++) { }

Are named for loops just stylistic or?

 
parent: for ( ... ) {
     child: for ( ... ) {
         if (exitConditionParent) break parent;
     }
}

You could do a labeled while loop as well.

I don't advocate or not advocate that anyone use this technique just that it's there and it's trivia.

 

Yeah I see. Interesting either way, thanks.

code of conduct - report abuse