title: Error : can't read "line2": no such variable in tcl
body: <p>I have a script with this snippet:</p>
  
  <pre><code> while {[gets $fin line] != -1} {
   if {[string first "Modem :" $line] != -1} {
              set line2 [string range $line 17 end]
              puts $fout "One : \t$line2"
      }
  
      puts $fout "Two : \t$line2"
   }
  </code></pre>
  
  <p>The <code>One :</code> works and prints the output (when i don't include the <code>Two :</code> part in the script) but when I include <code>Two :</code> , it shows </p>
  
  <pre><code>error : can't read "line2": no such variable
      while executing
  "puts $fout "Two : \t$line2""
      ("while" body line 14)
  </code></pre>
  
  <p>Doesn't it hold the value of <code>line2</code> after coming out of <code>if</code> ?</p>