Programming Journal #1

in #javascript7 years ago

Intro to Rixi's Programming Journal

Hey guys, I'll be beginning to post new and interesting facets of Javascript (and soon comparisons of Javascript with Java) learnt throughout the week.

Javascript Labels

Image of Javscript

Scenario: You are in a nested if statement and want to break out of a loop (i.e. a for or while loop). A breakwill only exit out of the current block it's in. So if you're trying to break out once you hit a condition, you will need consecutive breaks to eventually, exit out of your loop.

This can get messy, and pollute your code.

Comes in the label.

currentWhileLoop: while( fooBar === true) {

Using this line below:
break currentWhileLoop;

will break you out of the loop, regardless where you place this statement.