do

Loops through the statements enclosed within the { code block } until the following while test expression is false:

 

do {
statements ;
} while (test expression) ;

 

*note the ending semi-colon ; after the while test expression!

 

#include <iostream>
using namespace std ;

int main () {

	int myVar = 0 ;

	do {
		cout << "myVar is now: " << myVar << endl ;

		myVar++ ;
	} while ( myVar < 5) ;

	return 0;
}

Compile & Run:

myVar is now: 0
myVar is now: 1
myVar is now: 2
myVar is now: 3
myVar is now: 4

Leave a Reply