Pattern: Undefined loop variable
Issue: -
Avoid using loop variable outside of loop as it might be undefined. This may lead to unexpected behavior and act as source of bugs.
Example of incorrect code:
def do_stuff(some_random_list):
for i in some_random_list:
print i
print i # [undefined-loop-variable]
Example of correct code:
def do_stuff(some_random_list):
for i in some_random_list:
print i