title: How I can make list length method in scala?
body: <p>I need to make function that will be returning list length (of course without standart scala method)</p>
  
  <pre><code>val a = 3 :: 4 :: 7 :: 9 :: Nil
  var b = 0
  var i = 0
  def listLength[A](xs: List[A]): Int = {
  if (xs(i) != null &amp;&amp; i &lt; xs.length)
    b += 1
    i += 1
  listLength(a)
  b
  }
  println(listLength(a))
  </code></pre>
  
  <p>For this method I have an error: java.lang.IndexOutOfBoundsException: 4</p>