in reply to RE: why does a for loop parse like this?
in thread why does a for loop parse like this?

i understand that much... i guess what is confusing to me, is the fact that the parser changes all for loops into while loops with some sort of "post loop modifier" called continue... what I really don't understand is, why was the design desicion made to deal with this in this way? is this the way all languanges handle "C style for constructs?" 'cause if it is, that's really a VERY interesting little bit of information to keep in the very back of my head...
  • Comment on RE: RE: why does a for loop parse like this?

Replies are listed 'Best First'.
RE: RE: RE: why does a for loop parse like this?
by atl (Pilgrim) on Jul 19, 2000 at 21:20 UTC
    To quote Nikolaus Wirth on this one: the "for" loop is just syntactic sugar. There is no need for the different type of loops, they are just nice to look at (i.e. you can rewrite every loop using anoother one). That's why Oberon (successor of Modula 2, successor of Pascal) doesn't have a "for" statement.

    The reason why "for" is handled by rewriting it to a "while" construct: well, reuse, I guess. Since all loops are in essence equivalent, you choose one which is easy to implement and transform the others on the fly. Compiler gurus, your call ;-)

    Andreas