js conditional branch statement

Conditional branch statement

Conditional branch statements are also called switch statements.
Syntax:
switch (conditional expression) { case(expression): statement... break; case(expression): statement... break; default: statement... break; }









Execution process:
switch...case...statement

  • During execution, the expression after the case and the expression after the switch will be congruently compared;
  • If the result of the comparison is true,
    all the code behind the current case will be executed from the current case . Use break to end the switch statement
  • If the comparison result is false, then continue to compare downward.
  • If all the comparison results are false, only the
    switch statement and the if statement after the default statement are executed . The functions of the switch statement and the if statement are actually duplicated, and the two can be used instead

For example:
judge that the score is greater than or equal to 60 is qualified, and the score less than 60 is unqualified
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_48769418/article/details/107884165