Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  36] [ 1]  / answers: 1 / hits: 32769  / 14 Years ago, sat, february 5, 2011, 12:00:00

I just found out about using label s in JavaScript, such as:



for (var i in team) {
if(i === something) {
break doThis: //Goto the label
} else {
doThat();
}
}

doThis: //Label
doIt();


I've not heard about this until now and I can't find much information online about it and I'm beginning to think there is a reason for that.



It seems to me like this is similar to a GOTO statement in other languages and would be considered bad practice. Would I be right in assuming this?


More From » loops

 Answers
17

Those are loop breaker identifiers. They are useful if you have nested loops (loops inside loops) and using these identifiers, you can conditionally specify when and which loop to break out from.


[#93887] Thursday, February 3, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzs

Total Points: 710
Total Questions: 113
Total Answers: 100

Location: Nepal
Member since Sat, Jul 18, 2020
4 Years ago
cruzs questions
Thu, Nov 26, 20, 00:00, 4 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
Sun, Aug 2, 20, 00:00, 4 Years ago
;