It's kind of a strange question. You must see WHY it's looping forever. If the user enters Y then it will loop forever. That's how you wrote it. So to make it NOT loop forever you should write it in such a way that it doesn't loop forever. There are many ways that might be done. Here's one:
1 2 3 4 5 6 7
if (love == 'Y')
{
for (int i = 0; i < 10; ++i)
{
cout<<"I love physics";
}
}
(BTW, learn to use [code] [/code] tags so your code is readable like mine above.)
simple loops can be broken with the break statement:
do
{
error = things();
if(error)
break; //
}
while(true);
you can use a goto as well. goto is generally frowned upon but to get out of loops it is accepted.
do
{
error = things();
if(error)
goto fubar;
}
while(true);
fubar: