title: what is the difference between initializing a string outside the for loop and inside the for loop?
body: <p>I have two code's here there are the same, The only difference that I am using in the first code a string initialized inside the for loop, In the other hand I am using a string initialized outside the for loop but still   getting to different answer's</p>
  <p>string initialized inside the for loop :</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  int main() {
      for (int i = 0; i &lt; 10; i++) {
          string  TheString = &quot;******&quot;;
          
          if (i &lt; 3 || i &gt; 6)
              TheString+= &quot;     &quot;;
          else {
              TheString += &quot;aaaaa&quot;;
          }
          cout &lt;&lt; TheString &lt;&lt; endl;
      }
      return 0;
  }
  </code></pre>
  <p>the output is this shape :</p>
  <pre><code>******     
  ******     
  ******     
  ******aaaaa
  ******aaaaa
  ******aaaaa
  ******aaaaa
  ******     
  ******     
  ******     
  </code></pre>
  <p>string initialized outside the for loop :</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  int main() {
      string  TheString = &quot;******&quot;;
      
      for (int i = 0; i &lt; 10; i++) {
          if (i &lt; 3 || i &gt; 6)
              TheString+= &quot;     &quot;;
          else {
              TheString += &quot;aaaaa&quot;;
          }
          cout &lt;&lt; TheString &lt;&lt; endl;
      }   
      return 0;
  } 
  </code></pre>
  <p>the output is this shape :</p>
  <pre><code>******     
  ******          
  ******               
  ******               aaaaa
  ******               aaaaaaaaaa
  ******               aaaaaaaaaaaaaaa
  ******               aaaaaaaaaaaaaaaaaaaa
  ******               aaaaaaaaaaaaaaaaaaaa
  ******               aaaaaaaaaaaaaaaaaaaa
  ******               aaaaaaaaaaaaaaaaaaaa
  </code></pre>
  <p>I am really confused about what is happening and thank you in advance.</p>