3. SELECT statement

Source: Internet
Author: User

The C + + selection statement includes the IF statement and the switch statement:

if (condition) statement;

if (condition) statement Else statement;

Switch (condition) statement

comparison operator = =,! =, <, >=, <=.

The comparison value is true to return the bool value true, otherwise the bool value is returned as false.

Example of an IF statement:

if (a >= b) {
max = A;
} else {
max = b;

It's better to write the following:

Max = (a >= b)? A:B;

Switch can be another form of an if statement:

Switch (val) {
Case 1:
Do1 ();
Case 2:
Do2 ();
Error ();


1. The four basic types of char, short, int, long, and bool can be used for switch statements.
2. Float, double cannot be used with a switch statement.
3. The enum type, that is, the enumeration type can be used for the switch statement.
4. All types of objects cannot be used with switch statements.

Declaration in a conditional statement:

In order to avoid errors using unexpected variables, it is a good idea to introduce variables in the smallest scope, for example:

if (double tempd = Prim (val)) {
Left/= tempd;

3. SELECT 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.