Thursday, September 8, 2011

Which Loops to be used when?!

Hello all! ^_^
Today I thought to share an important information I came across one day while I was studying. I just recalled it and thought it might be good thing to share with all my friends and readers! - When to use which loop in C or C++. it is no hard-and-fast rule, but it is a general way. Though it would be better if you use them in a way, that they are easy to understand to you and others too! :)
The for loop is appropriate when you know in advance how many times the loop will be executed. The while and do loops are used when you don’t know in advance when the loop will terminate; the while loop when you may not want to execute the loop body even once, and the do loop when you’re sure you want to execute the loop body at least once. These criteria are somewhat arbitrary. Which loop type to use is more a matter of style than of hard-and-fast rules. You can actually make any of the loop types work in almost any situation. You should choose the type that makes your program the clearest and easiest to follow.

And ya! I just figured out making a tutorial for C/C++ ain't my cup of tea. I can make programs, maybe good programs, I maybe able to explain how things work and how to proceed to someone mano-a-mano, but writing it here is not kinda possible...So instead I would share some of my programs every now and then, but sorry, I cannot give small lessons, which I thought last Wednesday to do for you all every week. Hope you all understand.
Thank you! ^_^

No comments:

Post a Comment

Kindly keep the comments clean and make quality comments that would be worthy in making this blog better! :)