+ 2
Hello. I want to be able to exit a program whenever i like. For example, when i make a switch() and i press case 1, i want to
continue the program, not to exit it. Does this have something to do with the command return;??
4 Answers
+ 4
As far as I understood your query, you want to keep iterating as long as you enter '1'.
char choice = '\0';
do
{
//Statements
cin >> choice;
}while(choice == '1');
This loop will keep running as long as you enter 1.
Any value other than will terminate the loop.
+ 3
If the switch is inside a function, return will make the program leave the function but continue execution.
+ 2
Thank you! nAutAxH AhmAd
+ 2
int Number;
while(Name != EOF)
{
cin >> Number;
switch(Numbr)
{
case ... etc
}
}
// the EOF means -1
// unless u enter -1 the program keep executing
this kind if loop is called Sentinel-Controlled Repetition
the other one is Counter-Controlled Repetition
like
for (int i = 10; i <= 10; i++)