can someone give me an advice

i have a stupid question about "do", im a noob in c++
im using borland c++ atm.

do
{
cout<<"\n ORDER : ";cin>>order;
pay=0;
for(total=1;total<=order;total++)

my question is, can someone give me an explanation about it while i knew is a couple for "do" is "while"? how could it happen?

*it works perfectly 0 warning, 0 error
*sorry about my english
I believe you are asking about the difference between a do while loop and a while loop. Please correct me if this is not true.

A while loop is a pre-test loop it tests the conditions before executing the code. An example of this could be

1
2
3
4
5
6
7
int count = 0;

while (count < 5)
{
cout<<"Hi"<<endl;
count++;
}


This code would output Hi 5 times and tests that count is less than 5 before executing the code inside.

A do while loop is a post-test loop. It runs the code in the loop then tests if the condition is met. This guarantees the code inside is run at least one time (It's good for stuff like asking the user if they want to run the program again). Example:

1
2
3
4
5
6
7
int count = 0;

do
{
cout<<"Hi"<<endl;
count++;
}while (count < 5);


this code will also output Hi 5 times but even if the count was greater than 5 to start with it will still output Hi 1 time.

Not sure what's up with code snippet you posted in their but it has many issues but doesn't look like its all their.

Hope this helps
Topic archived. No new replies allowed.