Why is the C++ For Loop stopping by itself?
<p>This is really weird :S </p>

<p>Below in my code, I have a nested for loop of i and j. When I enter the value of 6 for n (when the program prompts for input) the for loop simply doesn't iterate properly, it stops at random places and continues with new values of i.</p>

<p>For n = 6, below is what stderr outputs (for values of i and j that I threw in for debugging inside my code)</p>

<p>(COMING IN NEXT UPDATE OF QUESTION)</p>

<p><strong>UPDATE</strong></p>

<p>Thanks to a very smart fellow of the community, the question was answerd before I got the chance to post stderr output.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;map&gt;
#include &lt;set&gt;
#include &lt;stack&gt;
#include &lt;queue&gt;
#include &lt;cstdio&gt;
#include &lt;cmath&gt;
#include &lt;cstdlib&gt;
#include &lt;cctype&gt;
#include &lt;ctime&gt;

#define DEBUG

using namespace std;


int main ()
{
    #ifndef DEBUG
        freopen ("DATA4.txt","r",stdin);
        freopen ("OUT4.txt","w",stdout);
    #endif

    for (int _t=0;_t&lt;5;_t++){
        int n;
        cin&gt;&gt;n;
        set&lt;pair&lt;int,int&gt; &gt; poss;
        for (int i = 1; i&lt;=n; i++){
            for (int j = 1; j&lt;=n; j++){
                cerr&lt;&lt;i&lt;&lt;" "&lt;&lt;j&lt;&lt;endl; //Why doesn't this show results 1 1 then 1 2 then 1 3, why does it go to 2 2?
                //cerr&lt;&lt;n&lt;&lt;endl;
                if (i*j&lt;=n){
                    int tmp1 = i, tmp2 = j;
                    i = max(tmp1,tmp2);
                    j = min(tmp1,tmp2);
                    //cerr&lt;&lt;i&lt;&lt;" "&lt;&lt;j&lt;&lt;endl;
                    poss.insert(make_pair(i,j));
                }
            }
        }
        cout&lt;&lt;poss.size()&lt;&lt;endl;
    }

    return 0;
}
</code></pre>
