简体   繁体   中英

looping back to a certain point in Python

I am making a game in python 3.3 and am using while True: and break to make a loop this is while True: print ("") print ("You must answer all questions in block capitals") print ("Welcome to maze runner") print ("To learn about the controls press C") print ("To learn the about the different types T") print ("To play press START") run = input () #controls while True: if run == "C": print ("To walk forward press W") print ("To turn left press A") print ("To turn right press D") print ("To turn around press S") print ("To block press B") print ("To open pack press E") print ("To open stats Press Q") print ("To go back to the main menu press M") return_to_main_menu = input () if return_to_main_menu != "M": break else: break

Is there a way to get the break after else to go back to the second while true and also to get the break after the if to go back to the first while true

Either combine boolean flags and breaks or wrap loop in try: except: ... and raise an exception instead of loop. Second option probably is not that efficient but can be simpler and more reliable then tinkering with boolean flags.

Not like you do it.

Restructure your code so that everything in the inner loop is in a function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM