if statement – if pass and if continue in python
if statement – if pass and if continue in python
Using continue
passes for the next iteration of the for loop
Using pass
just does nothing
So when using continue
the print
wont happen (because the code continued to next iteration)
And when using pass
it will just end the if
peacefully (doing nothing actually) and do the print
as well
0 not printed because of the condition if not element:
If the element is None, False, empty string() or 0 then , loop will continue with next iteration.
if statement – if pass and if continue in python
if not element:
In both examples, this will only match the 0
.
pass
This does nothing. So the next command, print element
, will be executed.
continue
This tells Python to stop this for loop cycle and skip to the next cycle of the loop. So print element
will never be reached. Instead, the for loop will take the next value, 1
and start from the top.