468,456 Members | 1,832 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,456 developers. It's quick & easy.

Help regarding Loops?

40
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are there instances that you must use a Do-while loops instead of a for loops or a while loop? or you can use any types of loops in any given problem?
Sep 9 '06 #1
2 2002
Banfa
9,051 Expert Mod 8TB
With the use of the break statement any loop can be used to mimic any other loop.

Generally I would use for loops unless I had a specific reason to use a while or do-while loop.

The do-while loop is unique of the 3 in that the loop code clock is always executed at least once. You will sometimes get situations where this is useful.

I would only use the while loop if I didn't really have a control variable that required updating on every iteration.
Sep 9 '06 #2
risby
30
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are there instances that you must use a Do-while loops instead of a for loops or a while loop? or you can use any types of loops in any given problem?
I tend to think of using a for loop when I know how many interations I want it to do, as when iterating over an array of a known size, and using a while loop when the number of iterations is unknown in advance, perhaps dependent on the users' choice of whether to proceed.
Sep 10 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by chahnaz.ourzikene | last post: by
7 posts views Thread by mx2k | last post: by
2 posts views Thread by | last post: by
reply views Thread by Paolo Tavalazzi | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.