Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Guys I am building a Billing Program(Project). I am a beginner and am coding this project on python using functions. I am using different functions for Menu and Veg non veg beverages etc...So first the Menu is printed and then the User Selects what he wants . But when he clicks Veg or Beverage Menu(for example) I display all the items on the respective Menu including option to exit. But I cannot exit or terminate the function using return. Can anyone suggest how to get out of the function and again return the MainMenu
using return or break*

What I have tried:

I have tried to use return and break.
Posted
Updated 4-Jan-20 19:54pm
Comments
Visweswaran N 5-Jan-20 2:48am    
Could you show me the code? From this, "But I cannot exit or terminate the function + break" I believe there is something like while loop before the return statement, use a debugger and see whether the program goes for the return statement. Also make sure it to return things from the while loop if the data gets matched or something.


Note: this is just an assumption, better conclusions can only be derived from looking into your code.

1 solution

Simple: break your code into multiple functions.
Create a function to display the menu and get a response.
Create a function to handle "Veg", and a separate one to handle "Beverage".
Then your main function sets up a loop, inside which it calls the menu, and uses the result to cal "Veg", call "Beverage", or to return from the main function if "Exit" is selected.

Make sense?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900