Three kinds of structure of the program

Source: Internet
Author: User

1. Sequential structure: Sequential execution of statements.

2. Branching structure: Select execution between two optional statement sequences by making a decision
(branch).

3. Loop structure: Executes a sequence of statements repeatedly when a condition is met
Ring).

If statement
1. The If statement can constitute a branching structure, which is judged according to the conditions given to determine the execution
A branch program segment.

The IF statement of the 2.C language has three basic forms.

The first form of the IF statement
if (conditional expression) {
Statement 1;
}
When the conditional expression is true, execute statement 1, otherwise skip statement 1 and proceed to the following
The statement.

Precautions
if (conditional expression); {
Statement 1;
}
Note that the above code expression is followed by '; ', resulting in the IF statement being an empty statement, enclosed in curly braces
Statement is not related to the IF statement, which executes statement 1, whether the condition is true or false.

The second form of the IF statement
if (conditional expression) {
Statement 1;
}else{
Statement 2;
}
When the conditional expression is true, statement 1 is executed, otherwise statement 2 is executed.

The third form of the IF statement
Syntactic form (cascading):
!
if (conditional expression 1) {
Statement 1;
} else if (conditional expression 2) {
Statement 2;
} else {
Statement 3;
}

If the conditional expression 1 is true, execute statement 1, if the conditional expression 1 is false, the condition table
Up to 2 is true, execute statement 2, if the conditional expression 1 and the conditional expression 2 are false,
Line Statement 3;

Conditional operators
Conditional expression? Expression 1: Expression 2
If the conditional expression is true, the value of the entire expression is the value of expression 1.
If the conditional expression is false, the value of the entire expression is the value of expression 2.
For example: int c = a > B? A:B;

Three kinds of structure of the program

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.