3 ms·
I'm surprised. I've always thought of labels as something to be used with goto. What is the purpose of labels in javascript, since it does not implement goto ?
by oelmekki 13y ago
I'm surprised. I've always thought of labels as something to be used with goto. What is the purpose of labels in javascript, since it does not implement goto ?
Do you have any idea if it was intended to be used as you describe ?
- VMG 13y agoThe best I can come up with is this: ANIMAL: if (isAnimal) { DOG: if (isDog) { POODLE: if (isPoodle) { if (color == green) { break POODLE; // we don't want green poodles } if (age > 10) { break DOG; // we don't want old dogs } if (weight > 20) { break ANIMAL; // we don't want heavy animals } // more poodle conditions } // more dog conditions } // more animal conditions }
- deleted 13y ago[deleted]
- 0x0 13y agoSeveral languages support labels with "break" and "continue". It's mostly useful to break out several layers at once (nested loops, etc). See for example Java: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html http://docs.oracle.com/javase/tutorial/java/nutsandbolts/bra...