JavaScript Language Basics 14

Source: Internet
Author: User
Tags terminates

The JavaScript loop statement------------------while Loop statement.

While when the loop condition is true, the loop state is maintained until the loop is exited when the loop condition is false.

The template is as follows:


The While loop statement contains a loop condition and a loop body, above when value is greater than 1 o'clock to print the value, when it is less than or equal to 1 o'clock to exit the loop (we should avoid a dead loop when using the while loop, that is, the loop condition is always false).

The above while Loop statement is the first to determine whether the condition is ture, and then executes. Let's take a look at the first execution, which is to execute at least once the loop body----------do...while () Loop statement:


In the appeal code, when value is greater than 20 o'clock to execute the loop body, the actual value is 10, but the result can be seen even if the condition is false,do...while also executed once.


The break statement and the continue statement in the Loop statement.

The function of the break statement is to terminate the loop statement and jump out of the loop; the function of the continue statement is to skip the current loop (the block of code under the Continue statement) and execute the next loop body directly.

Break statement:






Code explanation: When I equals 5 o'clock terminates and jumps out of the loop body.


Continue statement:






Code explanation: When I equals 5 o'clock terminates and skips the current continue after the loop body once and then executes.



Reprint Please specify source:http://blog.csdn.net/hai_qing_xu_kong/article/details/41385641 Emotional Control _


JavaScript Language Basics 14

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.