Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual

Page 21

Advertising
background image

Publication 2098-PM001E-EN-P — July 2002

Programming Motion Control in C

1-9

is executed, and the condition is re-evaluated. The loop terminates
when the condition becomes false. As with the while, the body of the
loop is enclosed by braces. The initialization, condition, and
increment can be any expressions.

The choice between while and for is arbitrary, based on which seems
clearer. The for is usually appropriate for loops in which the
initialization and increment are single statements and logically related.
It is more compact than while and it keeps the loop control statements
together in one place.

It is generally bad practice to use magic numbers like 1000 and 10000
in a program; they convey little information to someone who might
have to read the program later. One way to deal with magic numbers
is to give them meaningful names. A #define line defines a symbolic
name or symbolic constant to be a particular string of characters:

#define

name

replacement_text

Thereafter, any occurrence of name (that is not part of another name)
will be replaced by the corresponding replacement text. The name
has the same form as a variable name: a sequence of letters and digits
that begins with a letter.

You may have noticed that there is a return statement at the end of
main. Since main is a function like any other, it may return a value to
its caller, which in effect is the Ultra5000 operating system. This return
value is not currently used.

Advertising