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

  • 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 128
All the expressions are optional. If
condition-exp
is left out, it is assumed to be
always true. Thus, “empty” for statement is commonly used to create an endless
loop in C:
for ( ; ; ) {...}
The only way to break out of this loop is by means of break statement.
Here is an example of calculating scalar product of two vectors, using the
for
statement:
for (s = 0, i = 0; i < n; i++) s += a[i] * b[i];
You can also do it like this:
/* valid, but ugly */
for (s = 0, i = 0; i < n; s += a[i] * b[i], i++);
but this is considered a bad programming style. Although legal, calculating the
sum should not be a part of the incrementing expression, because it is not in the
service of loop routine. Note that we used a null statement (
;) for a loop body.
MikroElektronika:
Development
tools
-
Books
-
Compilers
121
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
Vue de la page 128
1 2 ... 124 125 126 127 128 129 130 131 132 133 134 ... 311 312

Commentaires sur ces manuels

Pas de commentaire