#include <conio.h> // include the necessary files
#include <iostream>
using namespace std;
void main()
{
int i = 0;
do{ // A basic do while loop
cout << "Loop 1 number: "<< i << endl; // print i
i++;
} while( i < 10);
i = 0; // reset i
cout << endl;
while ( i < 10) // an other way to use this loop
{
cout << "Loop 2 number: "<< i << endl; // print i
i++;
}
getch(); // wait for a key to be pressed
}
/****************************************************************************
NOTES:
*****************************************************************************
Learn how to use a Do While Loop.
Let us take a closer look at a Do While Loop:
----------------------------------------------------------------
do{
cout << i;
i++;
} while( i < 10);
----------------------------------------------------------------
do - do while loop
{ - start the loop
cout << i - print i
i++ - increment i (i=i+1)
} - continue
while(i<10)- repeat loop while i < 10 (if i > 10 end the loop)
----------------------------------------------------------------
Description:
Loop until argument is set.
Warning! The do while loop can crash your program if "done wrong".
-----------------------------------------------------------------------------
Download Visual C++ Source Code
I hope you found this c++ tutorial useful!
Don't forget to mention Apron Tutorials in your References!