title: Nested do-while loop inside a while loop
body: <p>Started to learn C++ and encountered an issue with a task.
  The task requires me to rewrite a nested for loop to a do-while loop inside a while loop. The outputs are very different so I think I did something wrong.
  The nested for loop:</p>
  <pre><code>  #include &lt;stdio.h&gt;
  
    main()
    {
       int i, j;
       for (i=1; i&lt;=3; i++) {   /* outer loop */
           printf(&quot;The start of iteration %d of the outer loop.\n&quot;, i);
           for (j=1; j&lt;=4; j++)  /* inner loop */
           printf(&quot;Iteration %d of the inner loop.\n&quot;, j);
       printf(&quot;The end of iteration %d of the outer loop.\n&quot;, i);
      }
      return 0;
   }
  </code></pre>
  <p>output:</p>
  <pre><code>The start of iteration 1 of the outer loop.
      Iteration 1 of the inner loop.
      Iteration 2 of the inner loop.
      Iteration 3 of the inner loop.
      Iteration 4 of the inner loop.
  The end of iteration 1 of the outer loop.
  The start of iteration 2 of the outer loop.
      Iteration 1 of the inner loop.
      Iteration 2 of the inner loop.
      Iteration 3 of the inner loop.
      Iteration 4 of the inner loop.
  The end of iteration 2 of the outer loop.
  The start of iteration 3 of the outer loop.
      Iteration 1 of the inner loop.
      Iteration 2 of the inner loop.
      Iteration 3 of the inner loop.
      Iteration 4 of the inner loop.
  The end of iteration 3 of the outer loop.
  </code></pre>
  <p>my code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  main()
  {
      int i, j;
      i = 1;
      j = 1;
  
      while (i &lt;= 3) {
          printf(&quot;The start of iteration %d of the outer loop.\n&quot;, i);
          do {
              printf(&quot;Iteration %d of the inner loop.\n&quot;, j);
              j++;
          } while (j &lt;= 4);
          printf(&quot;The end of iteration %d of the outer loop.\n&quot;, i);
          i++;
      }
  }
  </code></pre>
  <p>output:</p>
  <pre><code>The start of iteration 1 of the outer loop.
  Iteration 1 of the inner loop.
  Iteration 2 of the inner loop.
  Iteration 3 of the inner loop.
  Iteration 4 of the inner loop.
  The end of iteration 1 of the outer loop.
  The start of iteration 2 of the outer loop.
  Iteration 5 of the inner loop.
  The end of iteration 2 of the outer loop.
  The start of iteration 3 of the outer loop.
  Iteration 6 of the inner loop.
  The end of iteration 3 of the outer loop.
  </code></pre>
  <p>Am I missing anything?</p>