Home > Web Front-end > JS Tutorial > JavaScript for loop if judgment statement understanding

JavaScript for loop if judgment statement understanding

一个新手
Release: 2017-10-12 09:43:12
Original
2174 people have browsed it

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

for (initial value; loop condition; operation){

Code statements to be executed if the conditions are met

}

Initial value: initialized variable before loop, usually assignment expression: it is recommended to use var assignment to speed up the operation.

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

Operation: The expression to be calculated after each loop is usually an assignment expression such as increment ++ or decrement --.

The three parameters in the for statement, the first is an initialization variable, used to set the initial value of the number of loops; the second is a conditional operator or logical operator, used to determine whether the loop continues; The third is the statement executed after each loop, which actually increments or decrements the initialized variable.

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

if statement: Use this statement to execute the code only when the specified condition is true
if...else statement: Execute code when the condition is true, and execute other code when the condition is false
if...else if...else statement: Use this statement to select one of multiple blocks of code To execute the
switch statement: Use this statement to select one of multiple code blocks to execute

Efficiency issues in the execution of switch and if..else

if...else follows The usage of switch is the same, but the difference between the two is the issue of processing efficiency.

Under normal circumstances, you can use switch,

But for example, if (a > 1 && a < 100) In this case, you can only use if.

The above is the detailed content of JavaScript for loop if judgment statement understanding. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template