JavaScript: Switch statement
Could someone please explain why in a Switch statement when a CASE is matched (if a BREAK is not included), the code will continue through the remainder of the CASE statements even if their arguments aren't satisfied. For example: EXAMPLE 1: var x = 0, y = 0; for (i=0;i<=2;i++) { x = i; switch(x) { case 0: y = 100; break case 1: y+=10; break case 2: y+=1; } } document.write(y); The result of the above code would be 111 However, if the 'break' lines are removed, the result of the code would be 123. What is the purpose behind this? I was under the assumption that a switch statement was used in place of a nested if statement. But without the breaks, this is no longer replicating the results of a nested if statement. Could you please provide a contextual example of when this would be useful in day to day programming? Thank you for the help! PS: I realise that occasionally in my post, my jargon is perhaps incorrect. Please, could you correct me where I am wrong so that I can learn for the future?