title: AWK Numeric Variable treated as string
body: <p>[Ubuntu 14.04, GNU Awk 4.0.1]   </p>
  
  <p>I have a strange problem...  I am assigning a numeric value, that is retrieved from an input file, to a custom variable.  When I print it, it displays correctly, and printing its length displays the right number of digits.<br>
  However, when I use the variable in a loop, my loop stops when index becomes greater than the most significant digit of my variable. </p>
  
  <p>I have tried a For Loop, and now a While Loop, both suffer the same problem.</p>
  
  <p>With the file I'm processing, <code>samples</code> contains the value 8092, and the loop stops on the 9th iteration.</p>
  
  <pre><code>#!/usr/bin/awk -f
  BEGIN {
    samples = 0;
  }
  {
    ...
    samples = $24;
  }
  END {
    i = 1;
    while (i &lt;= samples ) {
      if (i&gt;samples) { print "This is the end.\n " i " is bigger than " samples;}
      i++;
    }
  }
  </code></pre>
  
  <p>I am very new to AWK, and can't see why this is occurring.  After reading a number of tutorials, I'm under the impression that AWK is able to convert between string &amp; numeric representations of numbers as required.</p>
  
  <p>Can someone help me see what I've done wrong?</p>
  
  <p><strong>Solution</strong>
  The answer was, as JNevill &amp; ghoti suggested, to add 0 to the variable.  In my case, the best place was just before the loop, as samples` is rewritten during the body of the AWK script.  Thanks.</p>