C language basics -- use if... Else if... Else statement to implement multi-branch selection Structure

Source: Internet
Author: User

Sometimes multiple conditions must be determined to determine what operations to perform. In this case, if... Else if... Else statement. The statement syntax is as follows:

 

If (expression 1)
{Statement Block 1} // code that meets the expression execution
Else if (expression 2)
{Statement Block 2} // code that meets the expression execution
Else if (expression 3)
{Statement block 3} // code that meets the expression execution
......
Else
{Statement block n} // code that complies with the expression execution


 

The execution process is described as follows.
(1) first judge expression 1. if its value is true, execute <statement Block 1> and end the if statement.
(2) if expression 1 is set to false, expression 2 is judged. if expression 1 is set to true, <statement Block 2> is executed and the if statement is ended.
(3) If expression 2 is set to false, continue to judge the values of other expressions.
(4) If the values of all expressions are false, execute <statement Block n>.


 

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.