JS Loop structure

Source: Internet
Author: User

Loop structure:

For while Do....while

For loop

for (variable initialization; conditional expression; variable update) {

???? Loop body

}

Description

???? First step: variable initialization is performed only once

???? The second step: to determine whether the expression is set up, the execution of the loop body is not established, then jump out of the loop

???? Step three: Expression set up execution loop body then variable update

???? 2-à3-à 4-à 2-à3-à4 until the expression is not set to exit the loop

???? Interlaced color of tables

99 Multiplication Table:

While

Grammar:

Variable initialization

while (conditional expression) {

???? Loop body

???? Variable update

}

Description

???? The loop body is executed when the conditional expression is formed, and the loop is exited instead

???? To prevent a dead loop we usually define a variable initialization outside of the loop and add a variable update to the loop body.

Do....while

Grammar:

do{

???? Loop body

}while (conditional expression)

Description

???? Execute the loop body and then judge the conditional expression first

???? If the expression is true, the loop body is executed, and the reverse is not performed.

???? To prevent a dead loop we usually define a variable initialization outside of the loop and add a variable update to the loop body.

The difference between a for loop and a while loop

Number of known cycles using for loop, unknown loop count using while

The difference between while and do....while

Do.. While the conditional expression is true, it executes once

While if the conditional expression is not true, it does not execute

JS Loop structure

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.