Branching with if and else in Crystal is straightforward.
To run the program, save it as if_else.cr and use the Crystal compiler:
Note that you don’t need parentheses around conditions in Crystal, but the end keyword is required to close each block.
Crystal doesn’t have a ternary operator like some other languages, so you’ll need to use a full if statement even for basic conditions. However, Crystal does have a shorthand syntax for simple if-else statements:
This syntax can be used for simple conditional assignments.