O'Reilly logo
  • Khaleque Mohammad Fazle Azim thinks this is interesting:

gcdLoop

From

Cover of Programming in Scala, Third Edition

Note

a and b should have their role reversed otherwise the while loop version and recursion version later are not same output wise

def gcdLoop(x: Long, y: Long): Long = { var a = x var b = y

while (b != 0) { val temp = b; b = a % b; a = temp; } a }