def fibUpTo(max) n1, n2 = 1, 1 while n1 <= max yield n1 # invoke block value n1, n2 = n2, n1+n2 # and calculate next end end