This is really confusing. I just started learning c++ from the PDF i bough from the cprogramming website. Il give you the codes first then explain. These are two different codes so im not redeclaring the string.
Code:
string password;
do
{
cout << "enter password" << endl;
cin >> password;
}
while (password == "foobar");
{
cout << "Correct Password";
}
//////////
Code:
string password;
while ( 1 )
{
cout << "Please enter your password: ";
cin >> password;
if ( password == "foobar" )
{
break;
}
}
cout << "Welcome, you got the password right";
Ok so what im confused about here is in the Do-While Loop its asking for the password that is "foobar" but when i type it in, the block does not execute, it keeps asking for the password. But in the loop below with the if statement, if i type in "foobar" the block does execute. I dont get why one executes, but the other doesnt when they are both written with ==