Control flow, Statements and blocks, Example 8 - grouping statements – Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual
Page 35: Control flow -23

Publication 2098-PM001E-EN-P — July 2002
Programming Motion Control in C
1-23
Control Flow
In this section you will learn about the functions that control the flow
of a C program. The functions include:
• Statements and Blocks
• If-Else
• Else-If
• Switch
• While, For and Do-While Loops
• Break and Continue
Statements and Blocks
A statement is a command to the computer. In C, any expression
followed by a semicolon forms a statement. A statement may or may
not do something. For example the statement,
long point;
declares the variable point, but the null statement (a semicolon by
itself)
;
does nothing.
A block is two or more statements grouped together by enclosing
them in braces. The braces cause the entire block to be evaluated as a
single statement. Without the braces, each statement terminating with
a semicolon is evaluated separately. Refer to the following two
grouping examples.
Example 8 - Grouping Statements
/* grouping example A - individual statements */
point = 0;
while (point++ < 12)
target = 10 * point + 2;
MoveAbsolute(target);
/* grouping example B - blocked statements */
point = 0;
while (point++ < 12)
{
target = 10 * point + 2;
MoveAbsolute(target);
}