Link to home
Start Free TrialLog in
Avatar of F-J-K
F-J-KFlag for Canada

asked on

Should I Use GOTO Statement in Switch Case? C/C++

Everytime user enters a wrong option, i want the switch case to be repeated. I do not want to use while loop since when switch case is broken, i will still be inside the loop which i do not want that. I suggest to put GOTO statement in default, but many says goto is very bad way of programming which discourage me from using it even though i find it very useful in this case. Do you think its appropriate to use goto in this situation? What other alternatives you have?

NOTE: i have never used goto & i won't really use it somewhere else in the program except if i'm desperate.

        getUserChoice();
	switch(userChoice)
	{
		case 1:
			//do something
			break;
		case 2:
			//do something
			break;
		case 3:
			//do something
			break;
		case EXIT:
			exitApplication();
			break;
		default:
			cout<<"Wrong choice..."<<endl;
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are working a relatively small project a goto statement shouldn't matter much but in a largest one i wouldn't use it.
Avatar of F-J-K

ASKER

I wonder how i didn't think of that! ....

THANKS