In article <ef**********@murdoch.acc.Virginia.EDU>,
jk********@gmx.net
says...
[ ... ]
You might be right. However, for loops in C++ were the very hardest thing
for me to learn: for more than 5 years I never touched a for loop and
expressed everything in while loops because, on the initial line of a for
loop, there is just too much stuff going on. It took me quite a while to
get my mind around this totally wicked, overly general syntax. For loops
were the last C++ feature that I could add to my vocabulary. Everything
else (including STL, try-throw-catch, templates, inheritance) was easy in
comparison. To this day, I find while loops easier to understand; but I
grew used to for loops for iterating over containers. I could write page
long rants about "for". But I guess, that's just me: so you are probably
right.
I suppose I have the "benefit" of having previously used PL/I do loops,
which make C and C++ for loops look simple by comparison. PL/I tried to
have the generality of the C for loop, but also the conversational style
of something like Pascal. If memory serves, this would have been
perfectly legal:
y = 1;
do i = 1 to 10 by Y, 21 by -1 to i while x < limit;
y = 2;
/* ... */
end;
Since it's undoubtedly not obvious to people who've only dealt with sane
languages, with a loop like that, i would take the following values:
1 2 3 4 5 6 7 8 9 10 21 20 19 18 17 16 15 14 13 12 11 10
[assuming the 'x<limit' part didn't cause a premature exit].
I.e. the assignment to 'y' inside the loop didn't affect the value of
'y' used by the loop body in the increment, and the assignments to 'i'
in evaluating the loop didn't affect the value that was compared against
in the second count specification.
Of course that's all based on distant memories, so I probably got a
detail or two (especially in the syntax) a bit wrong, but I suspect the
general idea comes through in any case. Then again, rules in PL/I were
like rules in English -- every one of them had so many exceptions that
every real situation was really just a collection of special cases...
--
Later,
Jerry.
The universe is a figment of its own imagination.