0% found this document useful (0 votes)
56 views4 pages

The Continue Statement:: Example

The continue statement skips the remaining code block in a loop and moves the program flow to the loop check expression to start the next iteration. When a continue statement is encountered in a loop, if the loop condition remains true it will start the next iteration, otherwise it will exit the loop. An example shows a continue statement used in a while loop to skip printing when the index variable reaches 5. The switch statement is used to perform different actions based on different conditions. It compares the expression value to successive case values and executes the associated block of code when a match is found. Examples demonstrate using switch statements to print corresponding month names or strings based on a number variable.

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)
56 views4 pages

The Continue Statement:: Example

The continue statement skips the remaining code block in a loop and moves the program flow to the loop check expression to start the next iteration. When a continue statement is encountered in a loop, if the loop condition remains true it will start the next iteration, otherwise it will exit the loop. An example shows a continue statement used in a while loop to skip printing when the index variable reaches 5. The switch statement is used to perform different actions based on different conditions. It compares the expression value to successive case values and executes the associated block of code when a match is found. Examples demonstrate using switch statements to print corresponding month names or strings based on a number variable.

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/ 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