User manual

RP6 ROBOT SYSTEM - 4. Programming the RP6
z++; // abbreviation for z = z + 1; which implies z is now 9
z++; // z = 10 // z++ is called “incrementing z”
z++; // z = 11 ...
z--; // z = 10 // z-- is called “decrementing z”
z--; // z = 9
z--; // z = 8 ...
We previously used the data type “char”. However in most cases we prefer standard
data types in all RP6 programs.
As an example, this: int8_t x;
is identical to: signed char x;
And this: uint8_t x;
is identical to: unsigned char x; // respectively for us this is also true for
“char” only as our char is by default a signed one because of an compiler op-
tion.
4.4.5. Conditional statements
Conditional statements using “if-else”-constructs play an important role in program
flow. They allow us to check whether a condition is true or false and decide if a specif-
ic program part is executed or not.
A small example:
1
2
3
4
5
uint8_t x = 10;
if(x == 10)
{
writeString("x is equal to 10!\n");
}
The declaration in line 1 defines an 8-Bit variable x and assigns the value 10 to it. The
succeeding if-condition in line 2 checks, whether the value of x is equal to 10. Obvi-
ously, this condition will always be true and the program will execute the succeeding
block. It will output “x is equal to 10!”. If we would initialize x with a value of 231 in-
stead, the program would not output anything!
Generally, an if-condition will always have the following syntax:
if ( <condition X> )
<command block Y>
else
<command block Z>
Using plain English language we may also read: “If X then do Y else do Z”.
- 68 -