Skip to content
Advertisement

Continue in if conditional python loop is not working

JavaScript

Results are

JavaScript

I was expecting that it would identify the first pattern DS in the first string in list a, then move to next element. However, it proceed to identify DY as well. What am I doing incorrectly? Any help is appreciated.

Thanks

Advertisement

Answer

Try to replace continue with break like this

JavaScript

Output:

JavaScript

сontinue actually means that you go to the next iteration of for loop. Since you have continue inside j loop it doesn’t influence on i loop and simply iterates more on j.

break instead stops iterations on j loop and let’s i loop to proceed on the next iteration

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement