Question

i'm using nester for loops and i want the first nested loop to finish before the second one starts. right now it iterates through the first value of each nested loop, and then the second etc rather than completing the first loop before starting the second loop. How do I accomplish get the first loop to iterate completely before moving on to the second loop?

for i in range(len(input_data[0])):
    #first loop
    for l in range(len(input_data[0][0])):
        if input_data[0][i][l] == 'X':
            output = output + input_data[1][i][l]
    #second loop
    for l in range(len(input_data[0][0])):
        ni = -i
        if input_data[0][i][l] == 'X':
            output = output + input_data[1][l][ni]
    #third loop
    for l in range(len(input_data[0][0])):
        if input_data[0][i][l] == 'X':
            output = output + input_data[1][l][i]

i have tried each loop using a different variable than 'l', but the same thing happens.

Was it helpful?

Solution

You need to repeat the outer loop for each inner one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top