for loop - Python continue Not Working Properly -


i writing method using python , believe continue statement not working properly. can explain me wrong there?

the method code below:

def xltolinkeddt(lst1, lst2, name1, name2):         logging.info(">> new iteration")         dates1, times1, dates2, times2 = [], [], [], []         i, (dt1, dt2) in enumerate(zip(lst1, lst2)):             if bool(dt1) + bool(dt2) == 1:                 name = name1 if not dt1 else name2                 issues.append("the %s date of trip no. %d must provided." %(name, i+1))                 dates1.append("")                 dates2.append("")                 times1.append("")                 times2.append("")                 logging.info("exiting loop")                 continue              logging.info(continued after bool condition.)             raise assertionerror("stop!") 

when run code error , following logging in 1 of iterations:

>> new iteration >> exiting loop >> continued after bool condition 

the code not supposed log both messages, 1 of them. when replaced continue break worked well. missing?

the code not supposed log both messages.

yes, is.

after code executes continue, loop moves beginning of block inside for-loop, in next iteration. if condition in if-block not met @ next iteration, behaviour describe.

in [5]: in range(10):     print("trying i={:d}".format(i))     if i%2 == 0:         print("`i` even, continuing")         continue     print("what doing here?")    ...:      trying i=0 `i` even, continuing trying i=1 doing here? trying i=2 `i` even, continuing trying i=3 doing here? trying i=4 `i` even, continuing trying i=5 doing here? trying i=6 `i` even, continuing trying i=7 doing here? trying i=8 `i` even, continuing trying i=9 doing here? 

as can see, there still what doing here? printed after i even, continuing notification, belongs later iteration of loop. if replace continue break, different behaviour:

in [6]: in range(10):     print("trying i={:d}".format(i))     if i%2 == 0:         print("`i` even, not continuing")         break        print("what doing here?")    ...:      trying i=0 `i` even, not continuing 

as can see, stops because (by our definition), 0 even.


Comments