summaryrefslogtreecommitdiff
path: root/tests/functional/r/reused_outer_loop_variable.py
blob: b244e99f5c2d5d2bab342d624b489e88f00760f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Tests for redefining an outer loop variable."""
from __future__ import print_function
__revision__ = 0

# Simple nested loop
for i in range(10):
    for i in range(10): #[redefined-outer-name]
        print(i)

# When outer loop unpacks a tuple
for i, i_again in enumerate(range(10)):
    for i in range(10): #[redefined-outer-name]
        print(i, i_again)

# When inner loop unpacks a tuple
for i in range(10):
    for i, i_again in range(10): #[redefined-outer-name]
        print(i, i_again)

# With nested tuple unpacks
for (a, (b, c)) in [(1, (2, 3))]:
    for i, a in range(10): #[redefined-outer-name]
        print(i, a, b, c)

# Ignores when in else
for i in range(10):
    print(i)
    if i > 5:
        break
else:
    for i in range(2):
        print(i)

# Ignores dummy variables
for _ in range(10):
    for _ in range(10):
        print("Hello")