bug me now / bug me later
Wade Richards
t-wader at microsoft.UUCP
Tue Jun 12 08:19:17 AEST 1990
In article <811 at sagpd1.UUCP> jharkins at sagpd1.UUCP (Jim Harkins) writes:
=}
=}Lets say you have the following (you ADA people, please bear with me):
=}
=} #define SIZE 6
=} #define STEP 2
=}
=}Which is better:
=}
=} a. for(i = SIZE; i != 0; i -= STEP)
=}or
=} b. for(i = SIZE; i > 0; i -= STEP)
=}
It depends on the situation.
If you know that i will exactly equal zero (as in this case), then I think
that's what you should test for. However, I would probally put:
assert( SIZE % STEP == 0 )
before the loop, to make sure nothing blows up, and (more importantly) to make
it quite clear what was at fault if it does blow up.
--- Wade
More information about the Comp.lang.c
mailing list