Shorthand If and unless in Ruby lang

The basic conditional if in ruby is like any other programming language.

if condition then

[statements to execute if condition is satisfied (true) ]

end

If only a statement needed to executed then we can use shorthand form of if. Statement is at front followed by if and condition.

Ruby also have unless for conditional branching. Difference is statement will be executed if condition not satisfied (false).

Try it yourself at irb ! Bye …

Leave a Reply

Your email address will not be published. Required fields are marked *