Please indicate the source if you want to reprint: http://blog.csdn.net/gaoxiangnumber1
3.1 Statements and Blocks
An expression followed by a semicolon is a statement.
Braces { and } are used to group declarations and statements together into a compound statement, or block. There is no semicolon after the right brace that ends a block.
3.2 If-Else
if (expression)
statement 1
else
statement 2
where the else part is optional.
Associating the else with the closest previous else -less if.
3.3 Else-If
if (expression)
statement
else if (expression)
statement
else
statement
3.4 Switch
switch (expression)
{
case const-expr: statements
case const-expr: statements
default: statements
}
Each case is labeled by one or more integer-valued constants or constant expressions. If a case matches the expression value, execution starts at that case. All case expressions must be different. The case labeled default is executed if none of the other cases are satisfied. A default is optional. Cases and the default clause can occur in any order.
3.5 Loops - While and For
while (expression)
statement
the expression is evaluated. If it is non-zero, statement is executed and expression is re-evaluated. This cycle continues until expression becomes zero, at which point execution resumes after statement .
for (expr1 ; expr2 ; expr3 )
statement
is equivalent to
expr1;
while (expr2 )
{
statement
expr3 ;
}
expr1 and expr3 are assignments or function calls and expr2 is a relational expression. Any of the three parts can be omitted, the semicolons must remain.
3.6 Loops - Do-While
Do-While body is always executed at least once.
do
{
statement;
}
while (expression);
The statement is executed, then expression is evaluated. If it is true, statement is evaluated again, and so on. When the expression becomes false, the loop terminates.
3.7 Break and Continue
A break causes the innermost enclosing loop or switch to be exited immediately.
A continue statement causes the next iteration of the enclosing for, while, or do loop to begin. The continue statement applies only to loops, not to switch.
3.8 Goto and labels
A label has the same form as a variable name, and is followed by a colon. It can be attached to any statement in the same function as the goto . The scope of a label is the entire function.
Please indicate the source if you want to reprint: http://blog.csdn.net/gaoxiangnumber1
Chapter 3
最新推荐文章于 2024-01-20 10:45:38 发布