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



Cover of Programming in Scala, Third Edition


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 }