10.10-javascript for loop if judgment statement

Source: Internet
Author: User
Tags logical operators

Today I learned the For loop in JavaScript and the judgment statement for if

for (initial value; loop condition; action) {

Code statements that meet the criteria to execute

}

Initial value: The initialization variable before the loop, usually an assignment expression: it is recommended to assign a value with Var, which can speed up the operation.

Loop condition: The condition to be evaluated before each loop, is the conditional operator in the operator category, the return value is true or false, and the loop is executed when the return value is true, or false when the loop is exited. (often i>=n; or with logical operators)

Action: The expression to be evaluated after each loop, usually increment + + or decrement--an assignment expression.

For the three arguments in the For statement, the first is the initialization variable, which sets the initial value of the number of cycles, and the second is a conditional or logical operator that determines whether the loop continues, and the third is the statement that executes after each loop, actually incrementing or decreasing the initialization variable.

if (condition) {
Code executed when the condition is established
}

If statement: Use this statement to execute code only if the specified condition is true
If...else statement: Executes code when the condition is true and executes other code when the condition is false
If...else If....else Statement: Use this statement to select one of several code blocks to execute
Switch statement: Use this statement to select one of several code blocks to execute

Switch with If. The efficiency of else's execution

If...else is the same as switch, but the difference between the two is the problem of handling efficiency,

In general, you can use switch,

But if, for example, if (a > 1 && a < 100) This is the case, you can only use if.

10.10-javascript for loop if judgment statement

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.