Javascript&jquery. Cyclic control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.