C
CDROOM
I want know what is the deffirence between
while loop , for loop and do while loop.
and when every one use.
while loop , for loop and do while loop.
and when every one use.
CDROOM said:I want know what is the deffirence between
while loop , for loop and do while loop.
and when every one use.
Any good C book will tell you this. Start here:CDROOM said:I want know what is the deffirence between
while loop , for loop and do while loop.
and when every one use.
Clever Monkey said:Any good C book will tell you this. Start here:
<http://en.wikipedia.org/wiki/Control_flow#Loops>
- for: when you want to iterate a relatively known and fixed number of times
- while: you want to iterate 0 or more times
- do ... while: you want to iterate 1 or more times
I'm not sure I see the difference you are stressing here. My advice wasRichard said:This is C, not BASIC. The number is not necessarily even relatively
known; but the set of things you want to iterate over is. In BASIC (or
Pascal, or...) you'd have to know the number of members of your set
before for-looping; in C, all you need to know is what its end looks
like.
Any good C book will tell you this. Start here:
<http://en.wikipedia.org/wiki/Control_flow#Loops>
- for: when you want to iterate a relatively known and fixed number of times
- while: you want to iterate 0 or more times
- do ... while: you want to iterate 1 or more times
Each one of these can be coerced to behave like the others so style has
a lot to do with how they are used (in many cases).
Clever Monkey said:I'm not sure I see the difference you are stressing here. My advice was
correct enough in the general sense. There is no requirement that the
loop contain a set of anything, in which case it is just a number of
times to iterate.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.