Re: Plzz Explain !!



Malcolm wrote:
"Andrew Poelstra" <apoelstra@xxxxxxxxxx> wrote in message news:m3ac5ystmo.fsf@xxxxxxxxxxxxxxxxx
"Malcolm" <regniztar@xxxxxxxxxxxxxx> writes:
However C will allow you to put absolutely anything within the statements.
The loop terminates when the middle bit evaluates to zero. So you can do
stupid things like putting printf()s in the condition.
Occasionally you will see for loops used sensibly with compex conditions,
but only very occasionally. My own view is that it is never the correct
thing to put operations with non- control side-effects in a for loop, but
other regulars may disagree for a few exceptional situations.

How do you feel about

for (ch; ch != EOF; ch = getc (fh))

Or variations on the theme? This extends nicely if you want to add a
variable to keep track of how many bytes are read.

Horrible. Fortran "for" wouldn't allow it.
My view is that for loops are for when you know the number of iterations on loop entry. If it is some sort of dynamic condition, while() makes more sense.
This is inherent inthe English language meaning of the words.
for fifteen times, do this

Dot really. For all the elements of the list... For all the characters in the file... For every valid input provided by the user...

For in English is used for lots of things.

while some condition or other holds, do that.

That is not how I would talk in English about processing a file or a linked lists or many other things.
--
Flash Gordon
.



Relevant Pages

  • Re: while (1) vs. for ( ;; )
    ... >> Why not code it like you would read it in English: ... > glance that the loop is an infinite one; ... > represents a condition that will become true when the loop is meant to ... That program WILL terminate sometime. ...
    (comp.lang.c)
  • Re: Number of rows in xls file
    ... No problem with English. ... I think I can figure out how to stop the loop from the ... Gerry Metze ... >> data on you sheet? ...
    (microsoft.public.excel.misc)
  • Re: how do people feel about exit function from loop
    ... never mind that structured programming says you shouldn't ... Imagine a complex loop rendered into English: ... The For w Exits starts off boldly, ...
    (microsoft.public.vb.general.discussion)
  • Re: while (1) vs. for ( ;; )
    ... Because clear English is not necessarily clear C. ... represents a condition that will become true when the loop is meant to ... I assume that anyone reading my code either is familiar with C, ...
    (comp.lang.c)
  • WHILE Loop not exiting
    ... I have utilized linked lists a number of times, in fact, in very similar circumstances to the ... char array // Max length set to 81 chars. ... I am using a WHILE loop to run through each structure, then using a FOR loop to make all the ... I am then moving the pointer-to-struct to point to the next structure ...
    (alt.comp.lang.learn.c-cpp)