As we are not using break statement in the program, so all names of the month starting the current month will get displayed.
case 1 to case 12 without using break statement.
In the above example we have used switch statement with several cases i.e.
It supports different sizes, labels, label positions, and UI customization. Now click on the button “Click Me” and the current month will be displayed as below: The JavaScript Toggle Switch Button control is a custom HTML5 input-type checkbox control that allows you to perform a toggle (on/off) action between checked and unchecked states. When the execution process is completed successfully we will get the following output:
Just open the file in the browser, you will see the below picture in the browser.
Save the file as switch_using_break.html in your system.
switch(month) is used to choose particular month from the available list of month.
Break statement is used to come out of the switch statement.
When none of the statement is executed, then the default statement is executed.
When you click on the button “Click Me”, the current month gets dispalyed.
We have declared a variable month, which is initialized to 4.
JavaScript Switch – SyntaxĬlick the button to display current month.ĭefault:document.write(" Select correct month!!!") ĭocument.getElementById("demo").innerHTML=x Break statement is used to come out of the switch statement. Depending on the value of variable, a particular statement will be executed and if no value matches with any of the available options then default value will be executed using default case statement. The switch statement is selection control mechanism which allows value of a variable or expression to change the flow of the execution using multiple options. There are several options to be chosen from the available ones. The switch statement is same as of if/else statement, instead using multiple if/ else statement we are using switch statement.