mardi 22 septembre 2015

functionalities of continue/ break on the code in Python and its output

For the following programs, I know that they are not valid but I'm asking the logic of the code. I don't mean to run this code, just to know the output that It shall print, and the functionalities of continue/ break. I'd appreciate your feedback/comment/concern on this.

for x in [1, 1, 2, 3, 5, 8, 13]:
    if 1 < x < 13:
        continue
    else:
        print x

Shouldn't the output to be : 2,3,5,8 since they are in the 1< x< 13 range? what does the continue does in this code? does it change the outcome?

found = False
for n in xrange(40,50):
    if (n / 45) > 1:
        found = True
        break
print found

I think it would print out 46, 47, 48, 49, 50. but that break in the code, does it simply make a pause on the process?

Aucun commentaire:

Enregistrer un commentaire