In a single-layer loop exit, use break to exit, so what is the multi-layer loop? Witty people use the flag identifier in the way, for example:
a=['a', 1,2,3,4]b=['b', 1,2,3,4]c=['C', 1,2,3,4]d=['D', 1,2,3,4]break_flag=0 whilebreak_flag==0:y_n=input ('A,yes or No:') ifY_n = ='N': Break elifY_n = ='y': forIinchA:Print(i) whileBreak_flag = =0:y_n_2=input ('B,yes or No:') ify_n_2=='N': Print('Exit') Break_flag=1elify_n_2=='y': forIinchB:Print(i) whilebreak_flag==0:y_n_3=input ('C,yes or No:') ifY_n_3 = ='N': Print('exit ... ') Break_flag=1elifY_n_3 = ='y': forIinchC:Print(i)
Simply put, the identifier is given a value, in the execution process, if you enter the key key, the identifier is changed to another value. When setting the loop, use the while flag = = ' initial value ', and if the flag value is changed halfway, the program exits because the "flag changed value" condition is not set in the multilayer loop.
One-click Exit for multi-layered loops in Python