Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: "for" loops (was Re: C++ vs. Modula Message-ID: <754@atanasoff.cs.iastate.edu> Date: 2 Feb 89 16:02:38 GMT References: <1611@csuna.UUCP> <7800002@gistdev> Reply-To: hascall@atanasoff.cs.iastate.edu (John Hascall) Organization: Iowa State U. Computer Science Department, Ames, IA Lines: 29 In article <7800002@gistdev> flint@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