Example: Basic IF statement in Crystal
Cystal supports both a put command and print command for output.
- puts adds a new line after the end.
- print does not add a new line.
a = 1 if a > 0 puts a puts "a = ", a print "a = ", a end
a = 1
Example: Basic IF-ELSE statement in Crystal
age = 43 if age >= 18 print "You are old enough to vote." else print "You are not old enough to vote." end
You are old enough to vote.