What is the difference between while and do while loop? Explain with examples.
Answer / Sonika Dubey
While and do-while loops are both control structures used for repetition in C++. The main difference between them lies in their execution behavior.nn1) While Loop: The while loop checks the condition at the beginning of the loop. If the condition is true, then the body of the loop is executed; otherwise, the loop terminates immediately without executing the loop body.nnExample:n```cppnint i = 0;nwhile (i < 5) {n cout << i << endl;n i++;n}n```n2) Do-While Loop: The do-while loop checks the condition at the end of the loop. Regardless of whether the condition is true or false, the body of the do-while loop is executed at least once before checking the condition.nnExample:n```cppndo {n cout << i << endl;n i++;n} while (i < 5);n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Is it possible to use a new for the reallocation of pointers ?
What is this pointer in c++?
Write a short code using c++ to print out all odd number from 1 to 100 using a for loop
What is a memory leak c++?
Define upcasting.
char *ch = "abcde"; char c[4]; how to copy 'ch' to 'c'?
What is the outcome of cout< a) 16 b) 17 c) 16.5
What is the difference between the compiler and the preprocessor?
Evaluate: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); a) 10 b) 11 c) 1
What is a buffer c++?
What are the total number of lines written by you in C/C++? What is the most complicated or valuable program written in C/C++?
What is the use of setprecision in c++?