JavaScript While loop tutorial

Source: Internet
Author: User

Within JS It also has a while loop and a Do While loop, and let's look at the while loop action and the example tutorial.

The number of times specified to execute the same code block in JavaScript or the specified condition is true.


Example
While

How to write a while loop. Use the while loop to run the same code block, and the specified condition is true.

<script type= "Text/javascript" >
i=0;
while (i<=5)
{
document.write ("The number is" + i);
document.write ("<br/>");
i++;
}
</script>

Do While loop
How to write this ... while loop. Use this ... while loop to run the same code block, and the specified condition is true. This cycle will always be executed at least once, even if the condition is false, since the statement is the test before the condition is enforced.

<script type= "Text/javascript" >
i = 0;
Todo
{
document.write ("The number is" + i);
document.write ("<br/>");
i++;
}
while (I <= 5)
</script>
In the While loop
The while loop is used when you want to loop execution and continue execution, while the specified condition is true.

while (Var<=endvalue)
{code to IS
    executed
}
Reprint Please note: http://www.111cn.net/wy/yw.html
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.