This forum is now read-only. Please use our new forums at discuss.codecademy.com.
Is 0 false in Ruby?
I've experimented with some if/else statements:
if 0 print "a" elsif 1 print "b" else print "c" end
This code prints out "a". Does 0 not false in Ruby?
No it's not. :) Zero is a value, and ALL values in Ruby are evaluated to true, EXCEPT for FALSE and NIL.
Nope, as far as i know, it's not like other languages.
false is false, 0 is an integer, and nil is no value.
true is true, 1 is an integer, and nil is no value
Numbers, strings, and all other values evaluate to true.
nil evaluates to false. However, nil is not strictly equal to false, because false is a boolean datatype while nil has no datatype.
if false print "a" elsif true print "b" else print "c" end
prints out b
edit: added more pointers