Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to nest loops N number of times python

I’m creating a program, which needs to nest loops N number of times. Is there any way to do this? Or do I need to do it manually?

Wanted result:

for i in range(N):
    #Do something
    for i in range(N-1):
        #Do something
        for i in range(N-2):
            #Etc, continues until the value in range is 0

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do that with recursion

def func(N)
    if N == 0: return
    for i in range(N):
        #do something
    return func(N-1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading