Record the usage of switch case, switchcase

Source: Internet
Author: User
Tags switch case

Record the usage of switch case, switchcase

We usually like to use it when making multiple conditions.

Switch (expression)

{

Case: constant 1

Expression 1;

Break;

Case: constant 2

Expression 2;

Break;

Case: constant 3

Expression 3;

Break;

....

Default: constant 4

Expression 4;

Break;

}

Here are some notes for you:

1. Only constants rather than variables can be contained in case;

2. in C #, a switch part is not allowed to be executed to the next switch part. That is to say, break must be added for each case part or a statement that can prevent the case from being executed to the next case, for example:

Case: constant 3

Expression 3;

Break;

Or

Case: constant n

While (true)

Expression n;

Yes.

It is ensured that the switch will not continue to go to the next switch;

3. default can be dispensable. When all cases are not satisfied, the expression in default will be executed;

Related Article

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.