While Loop Functional Programming In Scala