0% found this document useful (0 votes)
42 views3 pages

Switch Statement

The switch statement is used to select one of many code blocks to be executed based on different conditions. It allows a variable to be tested for equality against multiple case values, and executes the associated block of code for the matching case. The break keyword is used at the end of each case so that the next case is not executed accidentally. Examples demonstrate using switch statements to write text for different number values or months.

Uploaded by

rina mahure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Switch Statement

The switch statement is used to select one of many code blocks to be executed based on different conditions. It allows a variable to be tested for equality against multiple case values, and executes the associated block of code for the matching case. The break keyword is used at the end of each case so that the next case is not executed accidentally. Examples demonstrate using switch statements to write text for different number values or months.

Uploaded by

rina mahure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Switch statement:

The switch statement is used to perform different action based on different conditions

switch (condition)
{
case condition 1: code to be executed if condition is true
break
case condition 2: code to be executed if condition is true
break



case condition n: code to be executed if condition is true
break
default: code to be executed if condition is true

Example: 1
Write any javascript application for switch statement

<html><head><title></title>
<script language="javascript">
var a=2
switch(a)
{
case 1:
document.write("One")
break
case 2:
document.write("Two")
break
case 3:
document.write("Three")
break
default:
document.write("Not One Two Three")
}
</script>
</head>
<body>
</body>
</html>
Output:
Two

Example: 2
<html><head><title></title>
<script language="javascript">
var a=9
switch(a)
{
case 1:
document.write("January")
break
case 2:
document.write("February")
break
case 3:
document.write("March")
break
case 4:
document.write("April")
break
case 5:
document.write("May")
break
case 6:
document.write("June")
break
case 7:
document.write("July")
break
case 8:
document.write("August")
break
case 9:
document.write("September")
break
case 10:
document.write("Octomber")
break
case 11:
document.write("November")
break
case 12:
document.write("December")
break
default:
document.write("Please enter proper number between 1 to 12")
}
</script>
</head>
<body>
</body>
</html>

Output:
September

You might also like