Break and Continue Statements

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email
The Break statement is used to terminate a loop and transfer control to the statement following the loop. The break statement is usually used along with a conditional statement. The break statement consists of the break key word A may also have an optional label. The following example illustrates the use of the break statement. <html>
<head>

<title>Loops</title>

</helad>

<body>
<script language="JavaScript">
<!--
i=6;
while(i>0){
document.bgcolor="silver"
document.write("<center>"+"<h"+i+">"+"Welcome to Pentasoft"+"</h"+i+">"+"</center>)
if(i==4)break;
--i;
}
//-->
</script>
</body>
</html>



The Continue statement

The continue statement affects the execution of the for,while and do-while loops in which it occurs Unlike the break statement it does not terminate the loop, rather it terminates the execution of the loop's current iteration. The following example illustrates the use of the continue statement:

<html>
<head>

<title>Loops</title>

</helad>

<body>
<script language="JavaScript">
<!--
var i=0;
document.write("<h2>"+"The continue statement"+"</h2>")
do{
i=i+1;
if(i==4)continue
with(document){
bgcolor="aqua"
write(i + "Iteration" +"<br>")
}
}
while(i<10);
//-->
</script>
</body>
</html>



Domain Name Search

www.


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