[prev] 62 [next]

Assignment as Expression (cont)

Assignment-as-expression often used to simplify loops, e.g.

// read stdin one char at-a-time
while ((ch = getchar()) != EOF) {
   // do something with ch
}

rather than

ch = getchar();
while (ch != EOF) {
   // do something with ch
   ch = getchar();
}