June 2017
Beginner
330 pages
7h 30m
English
Ruby doesn't limit you to two conditionals; technically, you can place as many conditions as you want. Consider this example:
if (x == 10 && x == z) || x == y puts "from the if statement" end
This code will print the statement for you. This is because Ruby follows the order of operations (the same order of operations you learned in Chapter 04, Working with Numbers in Ruby), so it will check the code within the parentheses first. If this value is true, it sees the || statement, and since it already knows that the left side is true, it runs the code inside of the if statement.
If you change || to &&, then nothing gets printed because the second part of the conditional is not true.
Read now
Unlock full access