Sebastian Hungerecker
3/3/2007 5:31:00 PM
Mike Glaz wrote:
> 1. def fib_up_to(max)
> 2. i1,i2 = 1,1
> 3. while i1 <= max
> 4. yield i1
> 5. i1, i2=i2, i1+i2
> 6. end
> 7. end
> 8.
> 9. fib_up_to(1000) {|f| print f, " "}
>
> I'm familiar with yield passing values to the block and vice-versa. But
> I have no clue what is happenening in line 5.
Line 5 has nothing to do with the yield (which in this case just displays the
current value of i1). It assigns the value of i2 to i1 and the sum of the
values of i1 (before the assignment) and i2 to i2.
> (I've been programming for 10 years so I'm familiar methods, loops, etc.
> it's just this yield thing I don't completely understand especially line
> 5.).
Like I said: The yield (in line 4) only displays the value and line 5 has
nothing to do with yield.
HTH,
Sebastian
--
NP: Dire Straits - So Far Away
Ist so, weil ist so
Bleibt so, weil war so