Python Python Basics (2015) Shopping List App Second Shopping List App

Sebastiaan van Vugt
Sebastiaan van Vugt
3,466 Points

Does pass do the same as continue?

Instead of continue I tried to use pass in a while loop. Even though it runs it doesn't seem to do anything. Is it right that pass and continue are equivalent but that pass should be used in a for loop and continue in a while loop?

Thanks for insights on this matter.

1 Answer

Steven Parker
Steven Parker
173,812 Points

You can use "continue" in any kind of loop, but it cannot be used outside of a loop. It causes the loop to repeat immediately without waiting until the the current iteration completes. It might appear to be doing nothing if it's at the end of the loop.

On the other hand "pass" can be used in or out of loops. It serves only as a placeholder and doesn't do anything.

Sebastiaan van Vugt
Sebastiaan van Vugt
3,466 Points

Thanks a lot. I thought that pass could also interfere with the loop but now noticed that indeed it actually does not.