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