+ 2
Why does this code only output 1-3 not 4?? š
š²š² The range is 1..5 , and is supposed to break if i>3, but shouldn't the code be written as i>=3?? because it outputs "1, 2, 3" .... 3 is equal to 3 , not greater than . so it should output "1, 2, 3, 4" ???? for i in 1..5 break if i > 3 puts i end # outputs: # 1 # 2 # 3
2 Answers
+ 8
You print i AFTER the condition is evaluated.
when i is 3:
is 3 > 3?
No, don't break.
print 3;
when i is 4:
is 4 > 3?
Yes, break.
*Exits loop.*
If it were i >= 3, then the output would be: 1, 2.
Same as i > 2.
+ 2
thank you !!! š @Rrestoring faith