Apparently, lbl: break lbl; is perfectly valid in JavaScript (but not lbl: continue lbl;).
Is there any obscure use for this construct?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can put a label before any statment.
continueis only allowed inside loops (for, for-in, while, do-while) as already said by boltclock in the comments to the question.breakcan be used inside loops, switch-statements, and any statement (as already commented by rob-w).The above statement is valid. As already commented by frederic-hamidi “it breaks out of itself” and isn’t very useful by itself, but see example below of how it could be useful.
The above statement is invalid because it isn’t a loop.
An example of how break label could be used in a block:
Outputs:
This is an example of how break label could be used inside a loop:
Outputs:
This is an example of how continue label could be used inside a loop:
Outputs:
ECMA262:5 12.12