The difference analysis of JavaScript while statement and do While statement _javascript skill

Source: Internet
Author: User
While statement:
Copy Code code as follows:

var i = 1;
while (I<10)
{
document.write (i);
i++;
}

Do While statement:
Copy Code code as follows:

var i = 1;
Todo
{
document.write (i);
i++;

}while (I<10);
From the example above, let's analyze their two-point differences:

1. Because the while statement always detects the loop expression first, its loop body may not execute at once, and the Do/while statement detects the loop expression at the bottom of the loop, so its loop body is executed at least once.
A semicolon is added to the end of the 2.do/while statement because it ends with a looping condition rather than simply using curly braces to mark the end of the loop body.
Related Article

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.