There are certain conditions when we need to break out of a loop before the complete loop gets executed. Or, in some cases we want to break out of the loop because there may be chances of an error. With the execution of the break statement, program flow will resume to the next sequential statement following the loop.
Break brings control out, as the statements in the switch case executed. If the break statement were omitted from switch case, the interpreter would execute each and every statement in all the switch case structures.
var x = prompt("Write a number in between 1 to 4");
case "1": alert(‘x is 1′);
case "2": alert(‘x is 2′);
case "3": alert(‘x is 3′);
case "4": alert(‘x is 4′);
default: alert(‘x is not 1, 2, 3 or 4′);
Read the rest of this entry »