x = [1,2,3,4]
for i in x:
if i==2:
pass #Pass actually does nothing. It continues to execute statements below it.
print "This statement is from pass."
for i in x:
if i==2:
continue #Continue gets back to top of the loop.And statements below continue are executed.
print "This statement is from continue."
The output is
>>> This statement is from pass.
Again, let run same code with minor changes.
x = [1,2,3,4]
for i in x:
if i==2:
pass #Pass actually does nothing. It continues to execute statements below it.
print "This statement is from pass."
for i in x:
if i==2:
continue #Continue gets back to top of the loop.And statements below continue are executed.
print "This statement is from continue."
The output is -
>>> This statement is from pass.
This statement is from pass.
This statement is from pass.
This statement is from pass.
This statement is from continue.
This statement is from continue.
This statement is from continue.
Pass doesn't do anything. Computation is unaffected. But continue gets back to top of the loop to procced with next computation.
while True:; pass # Busy-wait for keyboard interrupt (Ctrl+C)
in the python docs confused me in the way, that I didn't find it clear weather it behaves equivalent to continue in this case or something else was intended. The first sentence "The pass statement does nothing." characterizes all the answers to my question, but somehow it didn't catch my eye. – Aufwind