I've read a book by Mark Lee, C++ absolute beginner, and one of the code snippet is :
while(true)
{
cout << description.c_str() << "\n\n";
int response = 0;
do
{
cout << "What would you like to do?\n";
if(enemy)
cout << "1) Attack the evil "
<< enemyName.c_str() << "\n";
else if(!enemy)
cout << " 1) Move to the next room.";
if(treasure)
cout << " 2) Pick up the "
<< treasureName.c_str() << "\n";
cin >> response;
}while(response < 1 || response > 2);
switch(response)
{
case 1 : if(enemy)
{
enemy = !enemy;
cout << "You slay the deadly "
<< enemyName.c_str() << "\n";
}
else if(!enemy)
return;
break;
case 2: treasure = !treasure;
cout << "You pick up the "
<< treasureName.c_str() << "\n";
break;
}
}
I think you can ignore about what this program intention is, but the question is, why the part of "while(true)" is exist ? I think, there are no ways out of the loop, right ? Because, I think the "true" value is always return 1, and the "while(true)" part is same with "while(true == 1)", so this loop is like infinity loop, am I wrong or ? Any help is appreciated.