One-click Exit for multi-layered loops in python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.