- 1
Quiz help
Can someone help me understand this problem. The solution was 5 and I just want a better understanding of how. x=0 for i in 2...4 x+=i end puts x
3 Answers
+ 3
In this cycle, the range is set from 2 to 4, (4 is not inclusive), that is:
1. x = x + i => x = 0 + 2
2. x = 2 + 3
+ 2
Ranges have inclusive and exclusive syntax
.. includes the last number while ... does not hence 4 is not included in the loop.
+ 1
How did you get 4=x. Is it always going to be assumed to be the max?