Skip to content

Files

Latest commit

 

History

History
25 lines (17 loc) · 484 Bytes

undefined-loop-variable.md

File metadata and controls

25 lines (17 loc) · 484 Bytes

Pattern: Undefined loop variable

Issue: -

Description

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