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

Adam Crockett 🌀 - Jan 24 '20 - - Dev Community

I have been in the JavaScript scene for maybe 6 years and I love it when I find that I really ought to know about something fundamental especially something that isn't exactly bleeding edge.

You know this guy?

for (...) {}
Enter fullscreen mode Exit fullscreen mode

The for loop is a loyal companion that reminds me of my dog, it's always there when I need it, it's finite attention span and predictable loyalty is commendable. For convenience to distinguish my dog from other less firmiliar dogs, I gave my dog a name, so instead of shouting 'dog' and getting all the dogs coming to bring my slippers I just get my dog. Ace!

My goodness if only I could name my for loops then I could address them by name and give the commands to do tricks like break and continue and kill okay that last one is not so easy to teach a for loop or a dog to do.

lizie: for (let paws of dogs) {}
Enter fullscreen mode Exit fullscreen mode

Sooo, is that valid? ^^^

Yup,

What's it for?

A nested loop can break it's parent using the name break lizie or continue that works as well. But if you break Lizzie I will send you the bill.

I hope you are as shocked as I was.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .