Home Tutorial Javascript Javascriptbasics JavaScript Break Continue Statement

 
 

JavaScript Break Continue Statement
Posted on: November 7, 2009 at 12:00 AM
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

Related Tags for JavaScript Break Continue Statement:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.