Python Forum
Python2.7 xrange for loops - repeating though values already considered? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python2.7 xrange for loops - repeating though values already considered? (/thread-9003.html)



Python2.7 xrange for loops - repeating though values already considered? - nick5990 - Mar-16-2018

Each g in g_values for the minimal code below is being looped through, however when the end of g_values is reached, the outside loop starts again. I can tell this since concat_g_p starts from 2_3 again.

I would like an explanation as to why this happens, and suggestions on what to do to fix it?

Minimal code:
g_values=xrange(2,3)
p_values=primes[0:1000]
h_values=xrange(2,100)
order_false_list=[]

for g in g_values:
    for p in p_values:
        concat_g_p=str(g)+"_"+str(p)
        print "concat_g_p is: "+str(concat_g_p)
        if concat_g_p in order_false_list:
            break
        elif g == p:
            ...
        else:
            for h in h_values:
                if h>=p:
                    #don't want to consider these since solutions of these already dealt with (non-unique)
                    h_solution_found=True
                    break
                else:
                    ...
                    order_false_list.append(concat_g_p)
...



RE: Python2.7 xrange for loops - repeating though values already considered? - Larz60+ - Mar-16-2018

please make code executable so testing can be done


RE: Python2.7 xrange for loops - repeating though values already considered? - nick5990 - Mar-16-2018

I can't edit my post since past the 10min time limit. I presume I need to repost?


RE: Python2.7 xrange for loops - repeating though values already considered? - Larz60+ - Mar-17-2018

You'll be able to edit after only a few posts.
Just re-post no one will chastise you