1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 <Scripttype= "Text/javascript">7 /*8 * Conditional branching statements are also called Switch statements9 * Syntax:Ten * SWITCH (conditional expression) { One * CASE expression: A * Statement ... - * BREAK; - * CASE expression: the * Statement ... - * BREAK; - * Default: - * Statement ... + * BREAK; - * } + * A * Execution Process: at * switch...case. Statement - * At execution time, the value of the expression after the case is compared with the value of the conditional expression after switch. - * If the comparison result is true, the code is executed from the current case. - * All code after the current case will be executed, we can follow a break keyword behind the case, - * This will ensure that only the statements after the current case are executed, and no other - * If the comparison result is false, continue down comparison in * If all comparison results are false, only the statements after default are executed - * to * The functions of the switch statement and the IF statement are actually duplicated, and using switch can implement the IF function, + * The same can also be used if the switch function, so when we use, we can choose according to their own habits. - */ the * //depending on the value of NUM, the output of the corresponding Chinese $ Panax Notoginseng varNum= 3; - the if(Num== 1){ + Console.log (" One"); A }Else if(Num== 2){ the Console.log ("Ii."); + }Else if(Num== 3){ - Console.log ("three");//three $ } $ - //------------------------------------------------------------------------------------------ - the Num= "Hello"; - Wuyi Switch(num) { the Case 1: - Console.log (" One"); Wu //use break to exit the switch statement - Break; About Case 2: $ Console.log ("Ii."); - Break; - Case 3: - Console.log ("three"); A Break; + default: the Console.log ("illegal numbers ~ ~");//illegal numbers ~ ~ - Break; $ } the the </Script> the </Head> the <Body> - </Body> in </HTML>
JS Base _ Conditional Branching statement: switch statement