|
Putting a label at the end of a code blockJeffrey P. Bigham |
|
Related ArticlesRelated Ads |
Today, I was writing Javascript with a nested loop. On a certain condition, I wanted the code to break out of the inner loop and skip to the next iteration of the outer loop. I thought, incorrectly, that I could just naively use a label for this purpose by putting the label at the end of the outer loop and breaking to it from the inner loop. It would have looked like this:
The Javascript interpreter barfed on this, however, because *apparently* it requires an actual statement to come after label definitions. In this situation, I don't want any statement to be executed and I can't just put the label at the beginning of the outer loop because I want i to be incremented and checked against the loop condition. To fix this, I just wrote continue as the statement. This is essentially a no-op, but it works! Below is the altered version of the code.
|
|
|
||