B
Brian Schröder
Maybe this question would be more adequate for the ruby-nuby forum , but
while I'm writing my lecture slides about ruby, I saw that a while loop
always returns nil. Eg.
i = 1 # => 0
i *= 2 while i > 100 # => nil
I would have expected the loop to return 128. Is there an intention behind
this? Just thought I'd voice my "least surprise" to see if for others this
is also against the POTS.
PS: If you want you can see this as a warmup for our first Quiz . What
is the most concise way to write this:
i = 1
loop do
i *= 2
break i if i > 100
end
which would simulate the behaviour I'd expect of the 2-liner above. (No
semicolons allowed)
while I'm writing my lecture slides about ruby, I saw that a while loop
always returns nil. Eg.
i = 1 # => 0
i *= 2 while i > 100 # => nil
I would have expected the loop to return 128. Is there an intention behind
this? Just thought I'd voice my "least surprise" to see if for others this
is also against the POTS.
PS: If you want you can see this as a warmup for our first Quiz . What
is the most concise way to write this:
i = 1
loop do
i *= 2
break i if i > 100
end
which would simulate the behaviour I'd expect of the 2-liner above. (No
semicolons allowed)