variable re-identification causing an infinite loop : <p>Why does this code cause an infinite loop:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
int main() {
    int y = 5;
    while (y &lt; 6) {
        int y = 7;
        cout &lt;&lt; y &lt;&lt; endl;
    }
}
</code></pre>

<p>yet removing the "int" in the while statement makes it run once normally?
(</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

int main() {
    int y = 5;
    while (y &lt; 6) {
        y = 7;
        cout &lt;&lt; y &lt;&lt; endl;
    }
}
</code></pre>

<p>)</p>
