Continue and pass

what is the difference between continue and pass. They are both used to skip a block of code.

Hey @taniya.r,

pass statement will skip the block and moves to the next statements in the outer blocks,
whereas continue will skip whole iteration and resume from next iteration.

for e.g

for i in range(5):
    if(i%2==0):
        pass
    print(i)

Output would be :
0
1
2
3
4
Bcoz it goes in the if staement but does nothing, and continue the execution from the next line.
whereas

for i in range(5):
    if(i%2==0):
        continue
    print(i)

Here, Output should be :
1
3

When it is going in if condition , bcoz we have used the continue statement it is skipping the next lines as well, and restart the loop with incremented i value

I hope this clears your doubt,
Thanks :slight_smile:

ok. Thank you for the help :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.