For loop only runs once c++ : <p>Hi im trying to run the drunk walk problem which is similar to flipping a coin. I have the code written but it only enters the for loop once instead of 1,000,000 times like I want it to. I cant see what I did wrong so I hope you all can point me in the right direction, Thank you.</p>

<pre><code>  cout &lt;&lt; "enter the starting position.\n";
  cin &gt;&gt; i;
  cout &lt;&lt; "At starting block " &lt;&lt; i &lt;&lt; endl;

  for(j = 1; j &lt; 1000000; j++)
  {

     while(i &lt; 8 &amp;&amp; i &gt; 1)
     {
        x = rand() % 3;
        if(x == 0)
        {
           i++;
           tot_mov++;
        }
        else
        {
           i--;
           tot_mov++;
        }
     }

    if(i == 1)
    {
       tot_pub++;
    }

    if(i == 8)
    {
       tot_hom++;
    }

  }

    avg_mov = tot_mov / 1000000;
    avg_pub = tot_pub / 1000000;
    avg_hom = tot_hom / 1000000;

    cout &lt;&lt; "Total moves " &lt;&lt; tot_mov &lt;&lt; endl;
    cout &lt;&lt; "Average moves " &lt;&lt; avg_mov &lt;&lt; endl;
    cout &lt;&lt; "Total Home " &lt;&lt; tot_hom &lt;&lt; endl;
    cout &lt;&lt; "Average home " &lt;&lt; avg_hom &lt;&lt; endl;
    cout &lt;&lt; "Total pub " &lt;&lt; tot_pub &lt;&lt; endl;
    cout &lt;&lt; "Average pub " &lt;&lt; avg_pub &lt;&lt; endl;

    return;
</code></pre>
