JavaScript For Loop

Source: Internet
Author: User

The loop in Javascript is used CodeSpecifies the number of executions (or when the specified condition is true ).
Javascript loop
When writing code, you often want to execute the same piece of code repeatedly. We can use loops to complete this function, so that we do not need to repeatedly write several lines of the same Code.
Javascript has two different types of loops:
For
Number of times a piece of code is cyclically executed
While
When the specified condition is true, the code for loop is executed cyclically.
Use the for loop when the number of scripts is determined.
Syntax: Copy codeThe Code is as follows: for (Var = start value; var <= end value; Var = var + step value)
{
Code to be executed
}

Instance:
Explanation: The following example defines a loop.ProgramThe starting value of I in this program is 0. Every time a loop is executed, the value of I will accumulate 1, and the loop will continue to run until I is equal to 10.
Note: The step value can be negative. If the step value is negative, you need to adjust the comparison operator in the for declaration.

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.