J
Jim Haungs
10.times do |i|
puts 'too big' and break if i > 5
puts "#{i} ok"
end
I would expect this loop to quit after printing 0 to 5, but it executes
all 10 times. I know "puts" return nil, but isn't "and" (as opposed to
&&) supposed to execute both sides of the expression even if one side
evaluates to false?
Expected output:
0 ok
1 ok
2 ok
3 ok
4 ok
5 ok
too big
Actual output:
0 ok
1 ok
2 ok
3 ok
4 ok
5 ok
too big
6 ok
too big
7 ok
too big
8 ok
too big
9 ok
puts 'too big' and break if i > 5
puts "#{i} ok"
end
I would expect this loop to quit after printing 0 to 5, but it executes
all 10 times. I know "puts" return nil, but isn't "and" (as opposed to
&&) supposed to execute both sides of the expression even if one side
evaluates to false?
Expected output:
0 ok
1 ok
2 ok
3 ok
4 ok
5 ok
too big
Actual output:
0 ok
1 ok
2 ok
3 ok
4 ok
5 ok
too big
6 ok
too big
7 ok
too big
8 ok
too big
9 ok