I came across a ruby method that was an iterative fibonacci sequence.(not recursion) There is a line in the code that I've never seen before and I'm not exactly sure what it is doing. Here is the method:
METHOD:
def practice(n)
return 0 if n == 0
num1 = 2
num2 = 1
n.times do
num1, num2 = num2, (num1 + num2)
end
num1
end
If someone could iterate though this and explain what is happening I would be forever thankful. But, mainly I don't understand this part of the code -
n.times do
num1, num2 = num2, (num1 + num2)
end
What does the num1, num2 = num2 do/mean??