title: Why is my for loop running and resetting in AWK?
body: <p>I just really can not seem to understand AWK and how it works. I have this code</p>
  
  <pre><code>    awk '{ for(i=0; i&lt;NR; i++)print i}'
  </code></pre>
  
  <p>My file I am reading has four rows with with five columns. 
  It ends up printing</p>
  
  <p>0<br>
  1<br>
  2<br>
  3<br>
  0<br>
  1<br>
  2<br>
  3<br>
  0<br>
  1<br>
  2<br>
  3<br>
  0<br>
  1<br>
  2<br>
  3<br>
  0<br>
  1<br>
  2<br>
  3<br>
  <br>
  Why is i resetting and getting printed out different so many times?<br>
  I just want to print one time for each line. I just can not seem to understand the for loops In AWK and printing out one line. Also could someone explain to me how AWK works?!? <br><br>I want to be able to go through each line and test an if statement if so print but my if statement will run just as many times as the lines in the program. I have tired looking everywhere for answers but there is just not enough stuff on AWK to find anything useful. I am looking for a pretty straight forward answer on how for loops, if statements, and how printing works in AWK. Thank you so much!!</p>
  
  <p>Update question:<br>
  I want to read a file that has this content<br>
  0 0 0 1<br>
  0 0 0 0<br>
  0 1 0 1<br>
  2 0 0 0<br>
  <br>
  I want to be able to go through each line and add all the numbers in the row and if the row's total is greater than 0 than print the line if not then do not print it.<br>
  also I want to be to just know how to go print a number for how many lines there are.<br>
  so if the file has 6 lines the output would be:<br>
  1<br>
  2<br>
  3<br>
  4<br>
  5<br>
  6<br>
  <br>
  Thank you again!</p>