+ 1

WHILE LOOPS

What is the difference between a while loop and a do-while loop? Practical examples would be appreciated.

16th Sep 2022, 1:38 AM
zighetamara
2 Respuestas
+ 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..
16th Sep 2022, 8:26 AM
Jayakrishna 🇮🇳
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.
16th Sep 2022, 8:52 AM
Filip Dobeš