I was being told that recursive calling should be avoided and so I tried to use the return to end the function and call back the main function. However, it does not work perfectly as I thought (the print statement in the main function is not being executed), may I know which part of the code is causing the issue or is there any other approach to deal with recursive callings?
def view():
print("View page")
while True:
view_option = input("Please enter 'back': ")
if view_option == '':
continue
elif view_option == "back":
return
# being told to not use main()
def main():
print("Main page")
while True:
main_option = input("Please enter 'view': ")
if main_option == "view":
view()
else:
continue
main()
OUTPUT:
Main page
Please enter 'view': view
View page
Please enter 'back': back
Please enter 'view':
EXPECTING OUTPUT:
Main page
Please enter 'view': view
View page
Please enter 'back': back
Main page
Please enter 'view':
main, theelse: continueserves no purpose, right? What would happen if you deleted it? Nothing would change. It would continue the loop anyway. And inview, bothbreakandreturnhave the same effect inside the loop, right? So theelifserves no purpose.