balibakbar
balibakbar

Reputation: 269

if statement nested in a for loop

c = file('cluster_info.txt')
for i in zip(ys[-10:],result): # has ten elements
    for j in c.readlines():
        cluster = j.split(',')
        if q in cluster:
            m = (q[i],cluster[0])
            f = pylab.figure() # code for plot starts here
            for n, fname in enumerate(m):
                image=Image.open(fname).convert("L")
                arr=np.asarray(image)
                f.add_subplot(2, 1, n)  # this line outputs images on top of each other
                pylab.imshow(arr,cmap=cm.Greys_r)
            pylab.title("%s, Top:Predicted,Bottom:Observed" %i[0])
            pylab.show()
        else:
            continue

This is a snippet from a larger code, and I expect to produce 10 images/plots but no plots are produced by python. I think I am not nesting the if and else: correctly in the for loop. Please tell me what is wrong here.

Upvotes: 1

Views: 3893

Answers (1)

gefei
gefei

Reputation: 19776

what is your intention of else: continue? if you want to continue with the outer loop (i), you'd better use else:break. otherwise you may just as well delete the else branch

also, i does not seem to be used in your loop at all? it can't be right

Upvotes: 2

Related Questions