"for" loops (was Re: C++ vs. Modula2)

Norman Diamond diamond at csl.sony.JUNET
Mon Jan 30 13:00:29 AEST 1989


In article <19579 at agate.BERKELEY.EDU>, bowles at eris.berkeley.edu (Jeff A. Bowles) writes:

[Praising C's for-loop over other languages' iterators]

>    If I had a nickel for every time, in Fortran,
>    that I needed a loop that ran from 0.0 to 1.0 by 0.1 (or the like) and
>    had to use INTEGER to do it.

If you do such iterations in floating-point, adding 0.1 each time
instead of multiplying an integer by 0.1, you will lose a lot of
nickels.  I wouldn't mind receiving them.  (The Vancouver Stock
Exchange did that kind of thing.  Eventually their computed index
of stock prices became about half of the correct value, and they
finally noticed they had a bug.)

>    Or Pascal, which lacked the "step" clause
>    so that you couldn't increment by more than what the language-designer
>    wanted.

This was not due to what the language designer wanted.  Remember that
he only had resources available for a small compiler and had to provide
maximal assistance to novice students in error checking.  Testing "for"
statements for overflow when the stepsize is not 1 is more difficult.
Now if you had complained that the modern version, i.e. the draft ISO
Extended Pascal standard, still doesn't allow it, then I would agree
with your complaint.

> The only thing I really miss is something you Unix-types will recognize
> from awk (and perhaps from Algol 68?) -
> 	for (t in table)
> 		process(table[t]);
> But that's another story....

Do you mean:  for (t in some_set) process (table[t]) ?
At least the draft Extended Pascal standard has this one.
-- 
Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp at relay.cs.net)
  The above opinions are my own.   |  Why are programmers criticized for
  If they're also your opinions,   |  re-inventing the wheel, when car
  you're infringing my copyright.  |  manufacturers are praised for it?



More information about the Comp.lang.c mailing list