Summary of Switch statements

Source: Internet
Author: User

Have always felt that the switch statement is superfluous, do not care how much. In some cases, however, the switch statement can actually save a lot of energy.

When there are multiple judgments, switch can improve the readability of the program,

The form of a switch statement:

    Switch (< expression e>)    {         case < constant expression v1>: [statement S1];           Case < constant expression v2>: [statement S2];        ...         ....  Case < constant expression vn>: [statement SN];         default:            [statement sn+1];    }


When the value of the expression E is equal to the value of one of the constant expressions in the case, all statements following the colon in the case are executed until the break statement jumps out.

If the case does not satisfy the value of the expression E, execute the statement after default, and if there is no default statement, jump out of the loop.

E can be an int float and other types ....

Summary of Switch statements

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.