title: Golang one line for loop
body: <p>I was trying to read in CSV file in Golang line by line with a for loop that required an if statement with a break to see if the error reading the file was EOF.  I find this syntax rather unnecessary when I could in java for example read the line inside a while loop conditional and simultaneously check for the EOF error.  I thought that declaring a variable inside of a for loop was possible and I know for sure that you can do this with if statements in Golang. Doing:</p>
  
  <pre><code>if v := 2; v &gt; 1{
      fmt.Println("2 is better than 1")
  }
  </code></pre>
  
  <p>The first snippet of code I have here is what I know to work in my program.</p>
  
  <pre><code>reader := csv.NewReader(some_file)
  
  for {
      line, err := reader.Read()
      if err == io.EOF {
          break
      }
      //do data parsing from your line here
  }
  </code></pre>
  
  <p>I do not know whether or not this second snippet is conceptually possible or just syntactically incorrect.</p>
  
  <pre><code>reader := csv.NewReader(some_file)
  
  for line, err := reader.Read(); err != io.EOF {
      //do data parsing from your line here
  }
  </code></pre>
  
  <p>Would like some clarification/benefits/conventions of doing it one way over another, Thanks :)</p>