6/18 Correct code still I have a question


#1

for num in 1..15
puts num
end

and this puts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1..15

My question is why does it put 1..15 at the end? Is it supposed to do this?


#2

This relates to normal console behavior since we're entering code at the command line. The natural thing for the interpreter to do is respond. The response is related to the last expression or value in the buffer. That's one possibility, anyway.

for num in 1..15
  puts num
end
puts "Done!"

Output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Done!
nil

This time we get nil since the last command (statement to us) has no return value or buffered expression.


#3

Thank you, that was bothering me for some reason. I like this way a lot better.