Nifty Javascript - Flow Control


Labeled Loops

Javascript supports statement labels and these can be referred to by the break statement. This allows code within nested loops to immediately break out of the outermost loop.

Break out of inner loop only:

var i=0

loop1:
  for (;;) {
    for (;;) {
      i++
      if (i==5) break
    }
    alert('within loop1')
    break
  }

alert('outside loop1')






Back to Table of Contents