You might have noticed that we have been using the term while loop instead of while expression. This is contradictory to the term if expression we have been using throughout the several previous lessons. So, why is it that we haven’t been calling while and do-while expressions.
This is because expressions have return values and while and do-while don’t result in any significant return value. Both loops have a return type of unit which, as mentioned in an earlier chapter, is just a void value; empty.
While pure functional programming languages have expressions and not loops, Scala still gives you the option of using while and do-while for imperative programming. However, like var, it is preferable for one to challenge themselves to not use while loops.