top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the scenarios when do..while is used?

+1 vote
488 views
What are the scenarios when do..while is used?
posted Jan 22, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

Syntax

do {
 body of loop; 
} while ( test expression );
answer Jan 22, 2015 by Salil Agrawal
0 votes

In addition to the Salil Agrawal's ans
You can use do { } while (); when you wnated that your code must be executed irrespective of the conditon i.e (while (condition)), atleast one time.
Then you can use do..while in that scenarios.

answer Jan 23, 2015 by Arshad Khan
Similar Questions
+2 votes

I'm curious as to why libstdc++ is using a RB-tree to implement std::set (details here
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/set and here https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/bits/stl_tree.h ),
when there are faster alternatives?

I'm mainly curious, because from all the people I've asked there hasn't been a single answer in favor of RB-trees, other than "they're already popular" or "easy to implement".

If you'd like more details on that, here's a link to my question on stackexchange http://cs.stackexchange.com/questions/41969/why-are-red-black-trees-so-popular,
where nobody has yet answered as well.

Using a variant of B-tree (or (a,b)-tree) should be faster, and everyone seems to suggest so, which makes me wonder what is the reason for picking RB-trees? This is not a question about their theoretical speed, but about real world behavior on real hardware with respect to CPU caches, etc.

...