For performance reasons it makes sense to stop a ‘for if’ loop running if it has provided the required outcome.
e.g. in this example we want to write the value of ‘i’ to the console when it is less than 5.
Without the break statement the loop would write the values 0,1,2,3,4 to the console, but continue to run a total of 10 times.
Consider the impact of a loop going through 100’s of dimension or measure member values.
for (var i = 0; i < 10; i++)
{
if (i >= 5)
{ break; } // Exit the loop when i is 5 or more
console.log(i);
}
Code language: JavaScript (javascript)
