A do-while loop acts just like a while loop, except the condition is checked at the end of each pass through the loop body. This means a do-while loop will execute at least once.
Syntax:
do {
// loop body
} while ( condition );
Example:
Example:
#include <iostream>
using namespace std;
int main () {
// do while loop example
int i=0;
do
{
cout << "Apple: "
<< i << endl; // output
i++; // increment counter
}
while(i < 5); // condition
return 0;
}
Output: