Conditional Logic in Ruby

Tutorial Difficulty Level

This is the conventional use of the `if` in perl. Notice that there is no need for curly braces (`{` and `}`). The body of the `if` ends with the appropriate keyword, `end``else` or `elsif`. The `then` word is generally optional, though you need it if you want to put start the body on the same line as the `if`, the way the last statement does.

As in most languages (excluding Python), indenting is not required, and is ignored by the interpreter. Of course, it is wise to indent in a way which reflects the structure of the code.