C + + Fourth Lesson selection structure

Source: Internet
Author: User

First, if statement:

The first case of a 1.if statement:

An if (expression) statement

The second form of the 2.if statement:

if (expression) statement 1

Else Statement 2

The third form of the 3.if statement:

if (expression 1) Statement 1

else if (expression 2) Statement 2

else if (expression 3) statement 3

else if (expression 4) Statement 4

Else Statement 5

Second, switch statement:

switch (expression)

{

Case constant Expression 1:< statement sequence 1>

Case constant Expression 2:< statement sequence 2>

...//Other case branches

Case constant Expression n:< statement sequence n>

default:< Statement Sequence n+1>

}

The sequence of statements for adjacent case branches is stored next to each other, executes a sequence of statements for a case branch, does not automatically end the case statement, but executes subsequent branches. So, add the statement "break;" Used to jump out of a switch statement and go to execute a subsequent statement.

Three, Boolean type:

The Boolean type name is bool and has a value of only two: true and false.

True is a Boolean constant that represents the truth value; False constants represent false values.

C + + Fourth Lesson selection structure

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.