ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey all,
I have a program, that starts with a menu of options (1-9).
for instance if i choose option 3, it then asks me a series of questions.
Im looking to stop execution of those questions (in the middle, via a special keyword), and return to the main menu.
how can i do this??
Currently i have a keywork "main" and it calls the main fuction, displays the menu, and you can continue from there. HOwever when that exits, the program continues execution where the "main" was called. this cannot happen.
yes, something like that, however i need a little more logic, each case statement directs to a certain function.
And for instance case 1, will redirect to a newItem function, and ask a series of questions. I need the ability to break in the functions (at any question) and not return execution) and redisplay the main menu, (back to the case statementS)
I really suggest you not to handle it with "goto"! I am sure always there is a better way than a goto; for example here you can return a dummy value and whenever you need to check whether the function exit normally or not check the return value and ...
yes, i understand that, however i cannot wait until the end of the function, i need a way to check after each user input, if we should exit the function or not..
is there an efficient way of doing this??
When you do your user input checking you want an if invalid/keyword, return(EARLY_TERMINATION_CONSTANT) to get back to the case code, where the return value is checked and if it is EARLY_TERMINATION_CONSTANT, you break and the main menu loop runs again.
Edit: I dont think you should ever call the main function, and also shouldnt use GOTOs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.