+ 1
WHILE LOOPS
What is the difference between a while loop and a do-while loop? Practical examples would be appreciated.
2 odpowiedzi
+ 1
It is an explained in lessons almost all courses. Complete lessons for details..
while is preconditional meaning, first condition is checked then on true only executed body and gets repeated this.
Do while, is post conditional, first loop body executed then on condition is checked, if true loop gets repeated.. So here loop body executed atleast once.
ex:
while( false)
{
cout << "Not printed this";
}
do{
cout << "will be printed this" ;
} while(false);
Hope it helps..
0
We can write this loops in some basic instruction like goto.
(While)
begging:
If (!false) goto endCycle;
Console.WriteLine("print this");
Goto begginig:
endCycle:
(Do)
beggining:
Console.WriteLine("Print this");
If(false) goto beggining;
Bassicli different is when you ask about jump condition. In while loop you are first asking an then doing code. In "Do" you are first doing code and after that you are asking about condition.