continue vs. pass in this IO reading and writing

Luca Menegotto otlucaDELETE at
Thu Sep 3 18:37:56 CEST 2015

Il 03/09/2015 17:05, kbtyo ha scritto:

> I am experimenting with many exception handling and utilizing
 > continue vs pass. After pouring over a lot of material on SO
 > and other forums I am still unclear as to the difference when
 > setting variables and applying functions within multiple "for"
 > loops.

'pass' and 'continue' have two very different meanings.

'pass' means 'don't do anything'; it's useful when you _have_ to put a 
statement but you _don't_need_ to put a statement.
You can use it everywhere you want, with no other damage then adding a 
little weight to your code.

A stupid example:

if i == 0:

'continue', to be used in a loop (for or while) means 'ignore the rest 
of the code and go immediatly to the next iteration'. The statement 
refers to the nearest loop; so, if you have two nested loops, it refers 
to the inner one; another stupid example:

for i in range(10):
     for j in range(10):
         if j < 5: continue
         do_something(i, j) # called only if j >= 5


More information about the Python-list mailing list