JavaScript break and Continue syntax and example tutorials, let's take a look at the tutorials below.
There are two special reports that can be used for internal loops: Break loop.
Example
Break statement
Break the loop with the breaking statement.
<body>
<script type= "Text/javascript" >
var i=0;
for (i=0;i<=10;i++)
{
if (i==3)
{
Break
}
document.write ("The number is" + i);
document.write ("<br/>");
}
</script>
<p>explanation:the Loop would break when i=3.</p>
</body>
Continue statement
Continue to use the declaration to break the current cycle and continue to value in the future.
<body>
<script type= "Text/javascript" >
var i=0;
for (i=0;i<=10;i++)
{
if (i==3)
{
Continue
}
document.write ("The number is" + i);
document.write ("<br/>");
}
</script>
<p>explanation:the Loop would break the "current loop" and continue with the next value when i=3.</p>
</body>
Output results.
The number is 0
The number is 1
The number is 2
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10
Explanation:the Loop would break the "current loop" and continue with the next value when i=3.
Okay, let's see.
JavaScript breakthrough and continue to speak
There are two special reports that can be used for internal loops: break and continue.
Break
The rest of the command will break the loop and continue to execute the following code after the loop (if any).
For example
<body>
<script type= "Text/javascript" >
var i=0;
for (i=0;i<=10;i++)
{
if (i==3)
{
Break
}
document.write ("The number is" + i);
document.write ("<br/>");
}
</script>
</body>
Output is.
The number is 0
The number is 1
The number is 2