JS Base _ Conditional Branching statement: switch statement

Source: Internet
Author: User

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

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.