C Programming 3rd-Process Control

Source: Internet
Author: User
C Programming 3rd --- Process Control

3.1 statements and paragraphs
The expression 'I = 0' plus'; 'is a statement,'; 'is the statement Terminator;
'{' And '}' enclose one or more statements to form a compound statement or paragraph.

3.2 If-else clause
Format: If (expression a) expression B else expression C
If expression a returns true, expression B is executed; otherwise, expression C is executed.
For example:
If (A> B ){
Return;
}
Else {
Return B;
}

3.3 else if clause
Else if (expression )...... Else if (expression )......
Multiple else if statements can be entered;
For example:
If (operator = '+ '){
Return (A + B );
}
Else if (operator = '-'){
Return (a-B );
}
Else if (operator = '*'){
Return (A * B );
}
Note: In if-else if-Else, else forms the IF-else relationship with the previous nearest if. It is recommended that if-Else on each layer be determined.

3.4 switch statement
Format:
Switch (exp1 ){
Case const-Exp: statements; break;
Case const-Exp: statements; break;
Default: statements;
}
The result of exp1 must be a constant integer expression, and the result after case is an optional constant integer value;
Multiple Case values can be used to execute the same action. When each paragraph ends, you must use break or return to end the switch call;
Default is optional. If all the current cases do not match, execute the statement after default.

3.5 While and for Loops
The while format is as follows:
Exp1
While (exp2 ){
Statements;
Exp3;
}
For format:
For (exp1; exp2; exp3 ){
Statements;
}
Exp1 is the initialization expression, exp2 is the judgment Expression, and exp3 is generally the conditional incremental processing;
The three for expressions can be omitted. Only when exp2 is true can the subsequent statements be executed, and exp3 can be executed again.

3.6 do-while loop
Exp1
Do {
Statements
Exp3
} While (exp2 );
The difference with while is that do-while executes a loop at least once. Note that it ends.

3.7 break and continue
Break terminates a loop; Continue ends a loop;

3.8 GOTO statement
Format:
......
Goto error;

Error:

......

[Disclaimer:

1) This content may come from the Internet, or I have sorted it out by myself. It only represents the opinions and opinions of the Internet and individuals!
2) This content is for reference only. Any reference to this content will cause any consequences and will be irrelevant to the original author and the author of this blog !]

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.