Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!mailrus!tut.cis.ohio-state.edu!husc6!uwvax!umn-d-ub!umn-cs!hall!pmk From: pmk@hall.cray.com (Peter Klausler) Newsgroups: comp.lang.c Subject: How not to write a loop, revisited Message-ID: <4538@hall.cray.com> Date: 1 Mar 88 16:36:29 GMT References: <560@naucse.UUCP> <1988Feb11.200149.25172@sq.uucp> <2115@bsu-cs.UUCP> <832@unmvax.unm.edu> Organization: Cray Research, Inc., Mendota Heights, MN Lines: 83 Keywords: floating point, reality, cold hard truths In article <832@unmvax.unm.edu>, mike@turing.UNM.EDU (Michael I. Bushnell) writes: > In article <296@draken.nada.kth.se> d86-ctg@nada.kth.se (Claes Thornberg) writes: > >... And thinking of simple things > >like not using real variables in for-loops isn't that hard... > > I see NOTHING which precludes: > float x; > for (x = 0; x < 20; x += .5) > printf("%f ", x); > The output would, of course, be > 0.0 0.5 1.0 ... 19.0 19.5 > But maybe the condescending poster didn't mean loop control variables. No, I'm sure that Claes did, for the use of floating point in loop control is a nasty habit that produces very unportable code. Michael's example might be all right, as the loop increment is a power of two, but, in general, the construct float start, end, incr, var; for (var=start; var