You are on page 1of 4

The continue Statement:

The continue statement tells the interpreter to immediately start the next iteration of the loop and
skip remaining code block.

When a continue statement is encountered, program flow will move to the loop check expression
immediately and if condition remain true then it start next iteration otherwise control comes out
of the loop

Example:

This example illustrates the use of a continue statement with a while loop. Notice how the
continue statement is used to skip printing when the index held in variable x reaches 5

<html>
<head>
<title>Title of the document</title>
<script language="javascript">
var x = 1
document.write("Entering the loop<br>")
while (x < 10)
{
x=x+1
if (x == 5){
continue // skill rest of the loop body
}
document.write( x + "<br>")
}
document.write("Exiting the loop! ")
</script>
</head>
<body>
</body>
</html>
Output:
Entering the loop
2
3
4
6
7
8
9
10
Exiting the loop!
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