[Tutor] Different between pass & continue

Steven D'Aprano steve at pearwood.info
Tue May 18 14:20:26 CEST 2010


On Tue, 18 May 2010 10:34:16 pm M. Bashir Al-Noimi wrote:
> Hi All,
>
>
> I couldn't understand the difference between pass and continue
> keywords, could you explain to me?


"pass" is a do-nothing statement. It literally does nothing.

"continue" is only allowed inside a for-loop or while-loop, and 
means "jump to the start of the loop". It is related to "break".

Consider the difference between these three loops:


>>> for x in (1,2,3):
...     print(x)
...     pass
...     print(x, "again")
...
1
1 again
2
2 again
3
3 again
>>>
>>>
>>> for x in (1,2,3):
...     print(x)
...     continue
...     print(x, "again")
...
1
2
3
>>>
>>>
>>> for x in (1,2,3):
...     print(x)
...     break
...     print(x, "again")
...
1
>>>



-- 
Steven D'Aprano


More information about the Tutor mailing list