bug me now / bug me later
Charles H. Sampson
sampson at cod.NOSC.MIL
Sat Jun 9 02:51:52 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)
>
>Where this makes a difference is suppose SIZE is changed to 7. Obviously
>'a' goes into an infinite loop, while 'b' stops. In the real world SIZE and
>STEP could be variables that have been input by a user and manipulated a
>gazillion times before being used in the for loop.
>
Neither is inherently better than the other; it depends on the problem.
If the problem requires that SIZE be a multiple of STEP, then a is preferable
because it reflects the problem requirement, but the requirement itself must
be validated at some point. If there is no required relation between SIZE
and STEP, then b reflects that fact and is preferable. (Of course, a is
wrong in the latter case, so b is strongly preferable.)
All of this is MHO, naturally.
Charlie Sampson, CSC
P. S. Anything written down here can be ignored. The poster would not ac-
cept my followup because I had included more than I had written. Strange,
I thought I had cut down the original article to the minimum needed to es-
tablish the context, then gave a compact response. Apparently that's not
good enough. The only solution in such a case seems to be to pad your
followup enough to get past that limitation. Seems to me that the limita-
tion is self-defeating. This is the end of my first try at padding.
More information about the Comp.lang.c
mailing list