Answers for "how does nested for loop work"

3

nested loop

for a in range(1,3):
    if a%2!=0:
        print(a,end=" ")
        
    for b in range(1,a+1):
        if b%5==0:
         print(b,end=" ")
         
        for c in range(a,b+1):
            if c%3!=0:
             print(c,end=" ")

    print()
Posted by: Guest on December-12-2021
1

nested loop

def something(a):
    for methodname in ['method1', 'method2', 'method3']:
        try:
            m = getattr(a, methodname)
        except AttributeError:
            pass
        else:
            return m()
    raise AttributeError
Posted by: Guest on December-19-2021
0

What is the purpose of a nested loop?

What is the purpose of a nested loop? 

Nested loops are useful when for each pass through the outer loop, you need to repeat some action on the data in the outer loop. For example, you read a file line by line and for each line you must count how many times the word “the” is found.
Posted by: Guest on November-19-2021

Code answers related to "how does nested for loop work"

Python Answers by Framework

Browse Popular Code Answers by Language