Owen Chayner
2011-03-11 05:15:27 UTC
I have recently started learning C++ by a book. I am trying to get a head start because i really have a passion for computers, and i want to do software engineering at uni. Anyways, as I so far understood, the difference between a while and a do loop is that before the loop is started, (in the while loop) the int that we are testing is already initialized.
For example:
char x = 'y';
while (x == 'y' )
{
cout <<"Play again?(y/n)
cin >> x;
}
cout <<"Okay, bye. ";
While using a do loop, we are testing it without know anything about the char (in this case).
Is that right? I really think that that is not the case, but that is how i understand it at the moment. The book doesn't really tell me that much on when to use one or the other loop. Can you guys explain this for me please?
Cheers.