The switch statement

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email
The switch statement is used when a condition results in more than two values. For each value of the condition a separate set of statements is declared. The syntax for the switch statement is:

switch (expression){
case value 1:
statements
break;
case value 2:
statements
break;

case value n:

statements

break;

default :

statements
}

The default block is executed when none of the case values match with the value of the expression. The following is example to show how switch works:
<html>
<head>
<title>Loops</title>
</head>

<body>
<script Language="JavaScript">
<!--
document.bgColor="aqua"
document.write("<h2>"+ 'The switch Statement" +" <h2>")
for(i=1;i<5;i++){

switch(i){

case 1:

document.write("This is the first case"+"<br>")
break;

case 2:

document.write("This is the second case"+"<br>")
break;

case 3:

document.write("This is the third case"+"<br>")
break;

case 4:

document.write("This is the fourth case"+"<br>")
break;
}
}
//-->
</script>
</body>
</html>



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.