title: Scala: Expression of type Unit doesn't conform to type List[List[Boolean]]
body: <p>I'm trying to produce a function that returns a List that contains Lists of Booleans in Scala. So far, the function looks like this:</p>
  
  <pre><code>def listListBool(n: Int): List[List[Boolean]] = {
     val empty: List[List[Boolean]] = null
     if (n == 0) {empty}
     else if (n ==1) {val bools = List(List(true, false))
  }
  </code></pre>
  
  <p>The 'else if' part of the statement flags up with the error: "Expression of type Unit doesn't conform to type List[List[Boolean]]" even though I have specified that the program needs to return a List of Lists of Booleans. I have also tried the following syntax:</p>
  
  <pre><code>else if (n == 1) {val bools: List[List[Boolean]] = List(List(true, false)
  </code></pre>
  
  <p>But the same error is still produced. Am I missing something really obvious here? I feel like have been staring at this for hours and I still can't quite grasp what I'm getting wrong.</p>
  
  <p>Please keep in mind that I'm quite new to Scala and I'm not entirely familiar with all the ins and outs of the language and its syntax.</p>
  
  <p>EDIT: I replied to some comments on this stating that an 'else' was due to be added following fixing this problem. Looking through your comments, I tried adding one anyway and that was what fixed it. I still don't quite understand how that changes the return type from being 'Any' to the correct type but it works none the less.</p>