Wednesday, 21 March 2018

How to use continue Statement in JavaScript


The continue statement can also be used to stop the execution of a loop. It does not exit the loop rather it executes the condition for the next iteration of the loop. Now here we create a web page named ContinueStatementUse.html which shows the use of continue statement.
####Showing the Code for ContinueStatementUse.html file#####
<!DOCTYPE html>
<html>
<head>
<title>Using continue Statement In javaScript</title>
</head>
<body background=”wall.jpg” text=”#ff98ff”>
<h1>How to work continue  Statement in the while loop</h1>
<SCRIPT type=”text/javascript”>
var count=0;
while(count<10)
{
++count;
If((count%2==0))
continue;
else
document.write(“count=”+count+”<br/>”);
}
document.write(“While loop exited”);
</SCRIPT>
</body>
</html>

Here the if……else statement inside the while loop contains a continue statement. The condition of the if …else statement checks whether or not the count variable is divisible by 2. If the count variable is divisible by 2 then the continue statement is executed. As a result execution of the loop is halted the remaining statements are skipped and the condition of the while loop is evaluated for the next iteration. Note that in this case the continue statement is executed for every even number between 0 and 10.

##### Showing the Output of ContinueStatementUse.html ######


No comments:

Post a Comment