C++ doWhile Loop Control Structure
In this Tutorial we will understand and learn the working of dowhile Loop statements in C++ programming language.
Loops are used in programming to repeat a specific block until some end condition is met.
A do while loop is similar to a while loop, except that a do while loop is guaranteed to execute at least one time. This is because unlike for and while loops, a do while loop checks its condition at the bottom of the loop structure. This is the only difference between a do while loop and other loops.
Syntax of Do While Loop statements in C++
do { statement(s); }while( condition );
Flow chart diagram of Do While loop in C++
Working of Do While Loop
- The codes inside the body of loop is executed at least once for the first time.
- Then, the test condition is checked.
- If the test condition is true, the body of loop is executed. This process continues until the test expression becomes false.
- When the test condition is false, do…while loop is terminated.
Do While Loop sample program in C++
//WAP to print "I am a Programmer" until USER enters 'x' #include<iostream> using namespace std; int main() { char myChar; do { cout<<"I am a programmer "<<"Enter x character to print the message again: "; cin>>myChar; } while(myChar=='x'); return 0; }