Why every program returns nil


I was just wondering, why every code returns nil at the end?
can anybody explain this doubt?



Not every code return nil. What's returned is what the last instruction gives.

If for example you try this code:

variable = "yolo"

You'll get "yolo" as a return, since variable equates to the string "yolo".

However, if you use this code:

variable = "yolo"
puts "yolo"

You'll get nil as a return, because puts returns nil.


Well, how about in the loop.... like languages.each { |element| puts element }
Why it did not return NIL at end.. why?


I suppose that's because the each method returns the object it was called on at the end of execution.