Loop control
JavaScript also provides some loop control functionality.
Break terminating Loops
Break can be terminated not only in a switch, but also in a loop.
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>do while Loop </title>
<body>
<script>
For (Var i=0;i<10;i++) {
if (i==6) {
Break ;
}
println (i);
}
function println (a) {
document.write (a);
document.write (' <br> ');
}
</script>
</body>
The Code 12 line break terminates the loop.
Continue
The Continue keyword tells the interpreter to start the next iteration of the loop immediately and to skip the remaining blocks of code.
When the Continue keyword is encountered, Cheng immediately moves to the loop-check expression, and if the condition remains true, it starts the next iteration, otherwise the control comes out of the loop.
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>continue</title>
<body>
<script>
var I=1;
While (i<10) {
i=i+1;
if (i==5) {
continue;//jump out of this cycle
}
println (' Current-pass: ' +i ');
}
function println (a) {
document.write (A + ' <br> ');
}
</script>
</body>
Javascript&jquery. Loop control