Share on Google+Share on Google+

JavaScript Break Continue Statement

Advertisement
JavaScript Break Continue Statement: In this tutorial you will come to know about the break and continue statements of JavaScript, given examples will help you to go through the concept of break and continue statements of JavaScript.

JavaScript Break-Continue Statement:

Generally we need to put the break statement in our programming language when we have to discontinue  the  flow of the  program. On the other hand continue helps us to continue the flow, like the flow of loops etc., JavaScript like other languages supports both.

Example 1(Break):

<html>
<head>
<title>Write your title here </title>
<script type="text/javascript" >
for(x=1;x<10;x++)
{
	if(x%5==0)
		{
			document.write("Divisible by 5");
			break;

		}
		document.write(x+"<br/>");
}
</script>
</head>
</html>

Output:

1
2
3
4
Divisible by 5

Example 2 (Continue):

<html>
<head>
<title>Write your title here </title>
<script type="text/javascript" >
for(x=1;x<=10;x++)
{
	for(y=10;y>=1;y--)
	if(x==y)
		{
			document.write("Same No.");
			continue;

		}
		document.write(x+"<br/>");
}
</script>
</head>
</html>

Output:

Same No.1
Same No.2
Same No.3
Same No.4
Same No.5
Same No.6
Same No.7
Same No.8
Same No.9
Same No.10

Advertisements

Advertisement

Posted on: November 7, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.