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:
   pass
else:
   do_something()


'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

--
Ciao!
Luca

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to