JavaScript----Loops

Source: Internet
Author: User

If statement
...
if (expression) {when and when, execute statement 1

EXECUTE Statement 1

}

If there is only one statement, you can do without {}, such as: if () immediately after the execution of the statement
...
if (expression) {If an expression is true, then execute statement 1

Statement 1

}else{Otherwise, execute statement 2

Statement 2

}
...

if (expression 1) {EXECUTE Statement 1 as set

Statement 1

}else if (expression 2) {No re-judgment expression 2

Statement 2
}else{are not established.

Statement 3

}
This is the same as we draw the flowchart, judging leap year, two conditions reached

Switch statement

...
Switch (parameter) {

Case 1:
Statement 1;
Break

Case 2:
Statement 2;
Break

Case 3:
Statement 3;
Break

Case 4:
Statement 4;
Break

Case 5:
Statement 5;
Break

Default
Statement 6
None of the preceding conditions have been reached, the last statement
}

Strict equality operator, does not trigger type conversion

Cycle

To do certain things repeatedly
1,while Cycle

1,while (expression 1) {//If the condition is true
Perform
Expression 2
}
Expression 3
Judge first, then execute. Prior loop
Description: First judge the expression 1, set up the execution Expression 2, and then continue to judge the expression 1, if not the execution of an expression 3

2,do while loop
2,do{
Expression 1
}while (expression 2);
Expression 3
First execution once, then judge, the posterior cycle
Description: First executes expression 1, in the judgment Expression 2, if established, continues to execute expression 1, does not establish the execution expression 3;

3,for Cycle
Expression 1: Determines the initial value of the loop and executes only once at the beginning of the loop;
Expression 2: Check the loop conditions, as long as the real follow-up operations;
Expression 3: Complete the follow-up, then go back to the previous step and check the loop condition again

3,for (expression 1, expression 2, expression 3) {
Expression 4

}

Executes expression 1 First, executes expression 2, executes expression 4, executes expression 3, and then executes expression 2
Continue jump out of this cycle
Break jumps out of the current loop only for loop use

JavaScript----Loops

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.