C-Language Process control structure-sequential structure, selection structure

Source: Internet
Author: User

C Language 3 Flow control structure: sequential structure, selection structure, cyclic structure.

Sequential structure

The simplest structure, without the need for keywords. The Yasuteru code sequence is executed step-by-step.

Select structure

(i) if simple to use

1) First structure: if

A) If the condition is true, the following statement is executed, otherwise it is not executed.

if (condition)

{

Statement 1;

Statement 2;

}

2) Second structure: If-else

A) If the condition is true, execute statement 1, otherwise execute statement 2.

if (condition)

{

Statement 1;

}

Else

{

Statement 2;

}

3) The third kind of structure: if-else if-else ...

A) First judge the condition 1, if set up to execute statement 1, others do not, if the condition 1 is not established, then check the condition 2, "note" If the condition 3 is established, then the preceding is not established. Only one of all statement blocks will be executed.

if (condition 1)

{

Statement 1;

}

else if (condition 2)

{

Statement 2;

}

else (condition 3)

{

Statement 3;

}

  (ii) Selection of structural-switch   

Switch (value)//is usually a variable

{

Case value 1:

Statement 1;

break;

Case Value 2:

Statement 2;

break;

Case Value 3:

Statement 3;

break;

Default:

Statement 4;

break;

}

Explanation: The structure compares the value to the value 1, and if it is equal, executes all subsequent statements until the break statement jumps out of the entire loop, and if none of the preceding conditions is satisfied, the statement following the default is executed. If the break statement is not written, subsequent statements are executed consecutively until the break statement is encountered or all statements are executed , and the subsequent judgment is ignored if the preceding conditions are true.

C-Language Process control structure-sequential structure, 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.