do loops?

ok so basically i want to know if i will ever use do loops?
what are they usefull for and am i going to need them?
And should i learn them.
Last edited on
Do-while loops can be helpful for many things. Right now I can use an example from the class I'm in. We use Do-while loops to constantly enter values for mathematics problems so you don't have to keep reopening the executable.

For example you can say
1
2
3
4
5
6
7
8
do
{
 printf("enter radius and height for a cylinder);
scanf("%lf %lf, r, h);
volume = (1.0/3)*(3.14)*r*r*h;
printf("Volume is %lf", volume);
}
while (r<=0 && h<=0);


something like that. I just made that up but you get the point. the while part at the end makes it easier that way if you have conditions you don't have to add if statements and then retype the entire line of code. similar to a while loop
closed account (zb0S216C)
do...while() loops are used to ensure that the statements within the braces are executed at least once. The other loops don't allow this behaviour. So, yeah, definitely worth learning. Compared to the other loops, the latter behaviour is the only thing that differentiates it from while(); apart from the do keyword.

Wazzak
Topic archived. No new replies allowed.