Sullivan Market

a web based full-circle development system



My C++ Tutorials - The Do While Loop

The Do-While Loop:
    To expand on your first real program once more, I will show you the proper syntax for a do while loop. This will allow the programmer to loop for a set amount of times. A do-while loop will allow for at lease one cycle due to the fact that there is no check until the end.

#include "stdafx.h"
#include "iostream.h"

int main(int argc, char* argv[])
{
int x;
x=1;
do{
if (x > 5)
{
printf("Hello World!\n");
}
else if (x < 5)
{
cout << "Hello out there!!\n";
}
x++;
}while (x < 10);
cout << "Hello out there!!\n";
return 0;
}

My C++ Tutorials - The While Loop

The While Loop:
    To expand on your first real program once more, I will show you the proper syntax for a do while loop. This will allow the programmer to loop for a set amount of times. A while loop will only allow for at lease one cycle if a specific condition is met and will only continue to loop so long as this condition is still being met.

#include "stdafx.h"
#include "iostream.h"

int main(int argc, char* argv[])
{
int x;
x=1;
while (x < 10){
if (x > 5)
{
printf("Hello World!\n");
}
else if (x < 5)
{
cout << "Hello out there!!\n";
}
x++;
}
cout << "Hello out there!!\n";
return 0;
}

Back To C++ Tutorials

©2012 SullivanMarket.com