Re: Plzz Explain !!
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 24 Aug 2006 03:38:13 +0100
Malcolm wrote:
"Andrew Poelstra" <apoelstra@xxxxxxxxxx> wrote in message news:m3ac5ystmo.fsf@xxxxxxxxxxxxxxxxx"Malcolm" <regniztar@xxxxxxxxxxxxxx> writes:Horrible. Fortran "for" wouldn't allow it.However C will allow you to put absolutely anything within the statements.How do you feel about
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.
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.
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
.
- References:
- Plzz Explain !!
- From: dev_cool
- Re: Plzz Explain !!
- From: Malcolm
- Re: Plzz Explain !!
- From: Andrew Poelstra
- Re: Plzz Explain !!
- From: Malcolm
- Plzz Explain !!
- Prev by Date: Re: puts() vs printf()
- Next by Date: Re: how to copy strings into a linked list?
- Previous by thread: Re: Plzz Explain !!
- Next by thread: Re: Plzz Explain !!
- Index(es):
Relevant Pages
|