JS study notes (3. Process control)

1. Disagreement

1.1 if condition

if (condition) {...} // execute if it is true, curly braces can be omitted for a single statement

if (condition) {...} else {...}// execute if if true, else execute else

if (condition 1) {...} else if (condition 2) {...} else {...} // if condition 1 is true, if condition 2 is true, otherwise execute else

1.2 switch

switch (parameter) {case fixed value 1: ... break; case fixed value 2: ... break; default: ... break;}

1.3 Ternary operation

expression? true: false

2. Cycle

2.1 for loop

for (let i = 0; i < x.length; i++) { ... } // continue跳过,break退出

2.2 while

while(expression) { ... } // continue to skip, break to exit

2.3 do while

do {... } while (expression) ; //continue to skip, break to exit

Remarks: use for for specific times, and while for unclear times

Guess you like

Origin blog.csdn.net/m0_65939803/article/details/131077667