Abl-electronic PIC Microcontrollers PIC16 Manuel d'utilisateur Page 126

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 312
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 125
Upon finding a match, program flow continues normally: following instructions
will be executed in natural order regardless of the possible case label. If no
case
satisfies the condition, the default case evaluates (if the label default is speci-
fied).
For example, if variable
i has value between 1 and 3, following switch would
always return it as 4:
switch (i) {
case 1: i++;
case 2: i++;
case 3: i++;
}
To avoid evaluating any other cases and relinquish control from the switch, ter-
minate each case with break.
Conditional
switch statements can be nested – labels case and default are
then assigned to the innermost enclosing switch statement.
Here is a simple example with
switch. Let’s assume we have a variable with only
3 different states (0, 1, or 2) and a corresponding function (event) for each of these
states. This is how we could switch the code to the appopriate routine:
switch (state) {
case 0: Lo(); break;
case 1: Mid(); break;
case 2: Hi(); break;
default: Message("Invalid state!");
}
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
118
MikroElektronika:
Development
tools
-
Books
-
Compilers
page
Vue de la page 125
1 2 ... 121 122 123 124 125 126 127 128 129 130 131 ... 311 312

Commentaires sur ces manuels

Pas de commentaire