English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

how many times does teh loop print "once"?

do{
cout<<"\n once";
}while(0)


please expalin too.

2007-02-28 21:30:18 · 5 answers · asked by book lover 1 in Computers & Internet Programming & Design

also can u tell HOW MANY times will "ONCE" be printed???

2007-03-01 03:03:15 · update #1

5 answers

just once.

a do{}while() runs at least once, even if the condition is false the first time..it checks the condition statement only after going thought it once.

unlike a do{}while() a simple while() checks the condition first so something like while(0) would never execute.

2007-02-28 22:12:03 · answer #1 · answered by blabla 3 · 2 0

Only once it will run...
The basic Difference between Do...While and While is
as follows

in do...while first it will execute the statement and will check the condition

in while first it will check the condition then if the condition is true it will execute or it will terminate the loop.

in your program u have used do while ...so it will display ur statement in cout
then it will check the condition it is false obviously so it will terminate the loop..

Got it?

2007-03-02 06:39:05 · answer #2 · answered by M S B 2 · 0 0

It wil lrun only once.
Sometimes the answers are in the questions only. Same thing here. Thats the reason it is printing once. :)

2007-03-01 06:15:38 · answer #3 · answered by manoj Ransing 3 · 1 0

Only once.

do{        //Starting do
cout<<"\n once";      // Printing "once" on console
}while(0)       //False condition, loop terminated.

 

2007-03-01 05:35:23 · answer #4 · answered by oohay_member_directory 4 · 3 0

Zero times. "while" means the condition is tested before executing the body of the loop.

2007-03-01 05:57:53 · answer #5 · answered by Anonymous · 0 3

fedest.com, questions and answers