Program Design Basics Chapter fifth programming of selection structure (knowledge point)

Source: Internet
Author: User
Tags nested switch

The fifth chapter design of the selection structure

The first part:

Summarize

1 A program structure that uses different program segments to process a certain condition is called a selection structure.

2 C-language selection statements include if and switch statements

3 Use the break statement to interrupt the execution of the switch statement.

4 using the goto statement, the program execution process can be unconditionally specific.

Part II:

Separate description

5.1 Select Structure program with IF statement design

5.1.1 a simple if statement

Conditions of use: meet the conditions on the execution, not satisfied will not be executed.

Format:

If (expression) {statement 1}

5.1.2 If_else Statements

Format:

If (expression 1) {Statement 1}

(Expression 2) {Statement 2}

5.1.3 Nested IF statements

Form 1:if (expression 1)

If (expression 2) statement 1

Else Statement 2

Else Statement 3

Form 2:if (expression 1) {

if (expression 2) statement 1

}else Statement 2

Form 3:if (expression 1) Statement 1

else if (expression 2) Statement 2

Else Statement 3

5.2 Designing a multi-branch structure program with switch statements

5.2.1switch statements

Format:

switch (expression)

case constant Expression 1: statement 1 (break;)

Case constant Expression 2: statement 2 (break;)

Case constant Expression 3: statement 3 (break;)

....................................

case constant Expression N: statement n (break;)

Default: Statement n+1

5.2.3 Nested SWITCH statements

5.3 Unconditional Turn statement (GOTO)

Format:

S

Goto S;

Add:

1: Digit: g=n%10

2:10-bit: s=n/10%10

3: Hundred: b=n/100%10

4: Thousand: q=n/1000%10

Program Design Basics Chapter fifth programming of selection structure (knowledge point)

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.