|
Ordering Information |
|
.: Ordering using our PayPal powered shopping cart (PayPal
account not required).
|
CAN232 : $79 |
|
|
|
|
|
CANUSB : $89 |
|
|
|
|
|
I2C232 : $79 |
|
|
|
|
|
I2CUSB : $89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Click here to View Cart and check out.
|
|
|
|
|
 |
 |
 |
Chapter 1i - Program Control : Switch Statements |
|
Switch Statements
A switch
construct is actually a series of statements that performs a
check and controls program execution based on that check. This
is more a structured if
statement and is constructed as follows;
switch( CASE_SELECT )
{
case
CONSTANT1: BODY1 ; break ;
case
CONSTANT2: BODY2 ; break ;
case
CONSTANT3: BODY3 ; break ;
case
CONSTANTn: BODYn ; break ;
default:
BODYd; break;
}
The CASE_SELECT statement causes the execution of a
matching case statement.
|
Example #1 |
Example #2 |
|
#define DIFF 0
#define ADD 1
int x, y, z;
x = ADD;
switch( x )
{
case
DIFF: y = y - z; break;
case
ADD: y = y + z; break;
}
|
void
ProcessSerialCommand( char rc )
{
switch(
rc )
{
case
'r': ProcessRcommand(); break;
case
's': ProcessScommand(); break;
case
't': ProcessTcommand(); break;
}
}
|
|
 |
|