[prev] 59 [next]

Fine Control (cont)

Example: scan a[N], stop on zero or at end, ignore negative values

for (i = 0; i < N; i++) {
   if (a[i] == 0) break;
   if (a[i] < 0) continue;
   sum += a[i];
}

/* vs */

for (i = 0; i < N && a[i] != 0; i++) {
   if (a[i] > 0) {
      sum += a[i];
   }
}