Ruby if, else and unless statement: The if expressions execute a single statement or a group of statements if a certain condition is met. It can not do anything if the condition is false. For this purpose else is used.
Syntax
1 2 3 4 5 6 7 | if conditional [then] code... [elsif conditional [then] code...]... [else code...] end |
Python Program
Ruby if statement multiple conditions with example.
1 2 3 4 | x = 10 if x > 8 then puts "x is greater than 8" end |
Output
1 2 | H:\>ruby abc.rb x is greater than 8 |
Use of Multiple Conditions
If two things are true at the same time, then this section is for you. Below is an example:
1 2 3 | if name == "David" && country == "UK" # ... end |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.