title: Scala first program - error
body: <p>This is my first program on Scala. So, I hope I'll get the immunity of stupidity. </p>
  
  <p>The code is a one line modification of a snippet from <code>Programming in Scala</code>. </p>
  
  <p>All I am doing is </p>
  
  <ol>
  <li>reading a text file</li>
  <li>iterating the lines of the file</li>
  <li>printing the max length of the lines in the file. </li>
  </ol>
  
  <p>That works. </p>
  
  <p>Now, when I try to <strong>print each line along with the length of the line</strong> with </p>
  
  <pre><code>println (eachLine + ":" + eachLine.length)
  </code></pre>
  
  <p>it throws an error. </p>
  
  <p>I understand from this <a href="https://stackoverflow.com/questions/2563550/why-does-one-of-these-statements-compile-in-scala-but-not-the-other">link</a> in SO that I am supposed to add a parenthesis somewhere. But where and why?</p>
  
  <pre><code>import scala.io.Source
  
  class Loops {
  
  }
  
  object Loops{
  
    def main (args:Array[String]){
      printAllLines("Hello123.txt")
    }
  
  
    def printAllLines(fileName:String){
  
      var maxWidth=0
      var lineIterator=Source.fromFile(fileName).getLines;
      lineIterator.foreach((eachLine:String) =&gt;
          println (eachLine + ":" + eachLine.length)
          maxWidth=maxWidth.max(eachLine.length) //Compilation ERROR at this line
  
      )
      Console.out.println (maxWidth)
    }
  </code></pre>
  
  <p>//THIS WORKS !!</p>
  
  <pre><code>def printAllLinesFor(fileName:String){
  
      var maxWidth=0
  
      for (eachLine&lt;-Source.fromFile(fileName).getLines.toList){
  
          println (eachLine + ":" +eachLine.length)
          maxWidth=maxWidth.max(eachLine.length)
  
      }
  
      println (maxWidth)
   }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>ERROR</strong> : value maxWidth is not a member of Unit
  //possible cause: maybe a semicolon is missing before `value maxWidth'?</p>