javascript break & continue

break statement is used to stop a loop, and execute the commands after the loop.

var sum=0;
for (var i=1;i<10;i++)
{
if (i == 5) break;
sum += i;
}
alert(sum); //10 = 1+2+3+4

continue statement is used to skip a step in a loop, and execute the next step of the loop.

var sum=0;
for (var i=1;i<10;i++)
{
if (i == 5) continue;
sum += i;
}
alert(sum); //40 = 1+2+3+4+6+7+8+9