"for" loops (was Re: C++ vs. Modula

John Hascall hascall at atanasoff.cs.iastate.edu
Fri Feb 3 02:02:38 AEST 1989


In article <7800002 at gistdev> flint at gistdev.UUCP writes:

>  ...  Therefore, there is no reason I can see that the language should not
>let you have an increment of .1, since it is quite clear exactly what I
>want it to do in this case: the compiler ought to be able to see (easily)
>that it needs to set up a dummy integer counter to actually control the
>loop, and divide by 10 at the top of the loop for you to give you the index
 
 How's it supposed to know to use 10? 
 When I do 1.0/0.1, I get 9.99999985...  Well, it's pretty close to 10,
 let's use that :-)

>    ... in the example cited, the question was whether to run the loop for
>10 or 11 iterations.  However, if the compiler does one division to make
>that decision & then codes an integer loop for you it's much more likely
>it will be what you wanted.)

  That's the whole problem with this!  I don't want code that's LIKELY
  to be what I wanted... I want the damn thing to do what I asked for.

  What's so hard about writing:

       for (i=0; i<10; i++) {
           f = 0.1*i;
	   /* etc */
       }

  John Hascall
  ISU Comp Center



More information about the Comp.lang.c mailing list