Run same loop twice, but getting different results
<p>I cannot figure this out, but say I have a depth-3 array of strings called "text".</p>

<p>How can it be that in the following code:</p>

<pre><code>print "FIRST"
for gate in text[1:]:
    print "GATE"
    for text in gate:
        print "TEXT"
        for entry in text:
            print "ENTRY"
            print what

print "SECOND"

for gate in text[1:]:
    print "GATE"
    for text in gate:
        print "TEXT"
        for entry in text:
            print "ENTRY"
            print what
</code></pre>

<p>I get different output for each loop.</p>

<p>"First"</p>

<pre class="lang-none prettyprint-override"><code>FIRST
GATE
TEXT
ENTRY
×

ENTRY
××××¨×ª ××"×£

ENTRY
××× ××××¨ ××©×× ××××××ª, ×××¢××× ×× ××× ××¤× ×©××ª, ××© ××× ×¨××ª ×¤× ×× ××× ××ª××× × ×××©××× ××¡××××ª××, ×× ×× ×××××ª ×¢× ×× × ××©×¨ ×¡×××××ª×× ×××¨×××ª ×¤× ××, ×× ×××× ×××©××ª ××××××ª ×¢× ××©×¨ ××ª×××§×ª ×××¨×× ××× ×¢× ×××©× ×¢×©×¨ ×¤× ××, ×¢× ×× ××© ××× ××©×¨ ××¢× ×× ×××©×× × ××××¨× ×¢××× ××××× ×¢× ×××¨×ª×. ×××© ××× ××©×¨ ××× ×××©××ª ××¢× ×× ×××××¨×ª ××¤×ª×¨×× ××©×× ×¡×××, ××× ××× ×¤×ª×¨×× ×××©×× ××¤×©×¨ ××××× ××¤× ××××§××ª××× ××ª××¦×××ª×××.

TEXT
ENTRY
××.
</code></pre>

<p>"Second"</p>

<pre class="lang-none prettyprint-override"><code>SECOND
GATE
TEXT
ENTRY
×
TEXT
ENTRY
×ª
TEXT
ENTRY
×
TEXT
ENTRY
×
TEXT
ENTRY
</code></pre>

<p>Each Loop is coded exactly the same and yet I get different output. How is this possible?</p>

<p><code>text</code> has been modified. Before the SECOND loop, <code>text</code> has its value taken from the last iteration of <code>for text in gate: ...</code></p>

<p>You should consider renaming the inner loop variable to something different.</p>

python