97
C-Control Pro Mega Series
© 2008 Conrad Electronic
5.2.6
Control Structures
Control structures allow to change the program completion depending on expressions, variables or
external influences.
5.2.6.1
Conditional Valuation
With a conditional valuation expressions can be generated which will be conditionally calculated.
The form is:
( Expression1 ) ? Expression2 : Expression3
The result of this expression is expression2, if expression1 had been calculated as unequal 0,
otherwise the result is expression 3.
Examples:
a = (i>
5
) ? i :
0
;
a= (i>b*
2
) ? i-
5
: b+
1
;
while(i> ((x>y) ? x : y) ) i++;
5.2.6.2
do .. while
With a do .. while construct the instructions can depending on a condition be repeated in a loop:
do Instruction while( Expression );
is being executed. At the end the Expression is evaluated. If
the result is unequal
0
then the execution of the expression will be repeated. The entire procedure
will constantly be repeated until the Expression takes on the value
0
.
Example:
do
a=a+
2
;
while(a<
10
);
do
{
a=a*
2
;
x=a;
} while(a);
The essential difference between the do .. while loop and the normal while loop is the fact that
in a do .. while loop the instruction is executed at least once.
Summary of Contents for C-Control Pro Mega Series
Page 1: ... 2008 Conrad Electronic C Control Pro Mega Series ...
Page 9: ...VIII Inhalt 2008 Conrad Electronic ...
Page 10: ...Part 1 ...
Page 17: ...Part 2 ...
Page 23: ...Part 3 ...
Page 41: ...32 Hardware 2008 Conrad Electronic 3 3 5 3 Component Parts Plan ...
Page 57: ...48 Hardware 2008 Conrad Electronic 3 4 5 3 Component Parts Plan ...
Page 58: ...Part 4 ...
Page 91: ...82 IDE 2008 Conrad Electronic ...
Page 92: ...Part 5 ...
Page 135: ...126 Compiler 2008 Conrad Electronic 31 1F US 63 3F 95 5F _ 127 7F DEL ...
Page 136: ...Part 6 ...
Page 231: ...Part 7 ...
Page 240: ......