Scala Foundation Course - Scala Loops


Welcome back. The next item on our list is the while loop.The while loop of Scala is a statement because it doesn't return a meaningful value. It always results in a Unit. The syntax is simple. Here is an example.


Scala also supports a do while loop. It works same as while loop except that it checks the condition in the end. Here is an example.

A Pure functional programming language doesn't offer a while loop and the do-while loop. Scala keeps it there to support the Imperative approach as well. You can use while loop to implement an algorithm that repeats until a condition change. However, the functional approach is to use recursion for such requirements. That's all about while loop.



You will also like: