User manual
RP6 ROBOT SYSTEM - 4. Programming the RP6
You may simply build endless loops with while- or for-loops:
while(true) { }
or
for(;;) { }
In both cases the command block will be executed “for ever” (respectively until the
microcontroller receives an external reset signal or the program terminates the loop
by executing the “break”-instruction).
For the sake of completeness we finish this overview by describing the “do-while”-
loop, which may be considered as an alternative to the standard “while”-loop. In con-
trast to “while-loops the “do-while”-loop will at least execute the command block
once, even if the condition is false at the beginning.
The loop-structure is as follows:
do
{
<command block>
}
while(<condition>);
Please remember to place a terminating semicolon! (Of course, standard while loops
will not be terminated with a semicolon at the end!).
4.4.8. Functions
Functions are a key element in programming languages. In the previous chapters we
already met and even used functions, e.g. “writeString”, “writeInteger” and of course
the main-function.
Functions are extremely useful for using identical program sequences at several loca-
tions of a program – the text output functions used in previous chapters are good ex-
amples for this. Copying identical program code to all locations where it is used would
be very unhandy. Additionally, we would unnecessarily waste a lot of program
memory in doing something like this. Using one single function allows us to modify
program modules at a single central location instead of modifying a great number of
copies. Using functions will simplify the program flow and help us to keep the over-
view.
Therefore C allows us to combine program sequences to functions, which are always
structured as follows:
<Return type> <Function name> (<Parameter 1>, <Parameter 2>, ... <Parameter n>)
{
<Program sequence>
}
- 72 -










