+ 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;??

22nd Aug 2019, 6:53 PM
-DSaus-
-DSaus- - avatar
4 odpowiedzi
+ 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.
22nd Aug 2019, 7:28 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
If the switch is inside a function, return will make the program leave the function but continue execution.
23rd Aug 2019, 2:07 AM
Sonic
Sonic - avatar
+ 2
Thank you! nAutAxH AhmAd
22nd Aug 2019, 7:35 PM
-DSaus-
-DSaus- - avatar
+ 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++)
23rd Aug 2019, 6:39 PM
Eyob
Eyob - avatar