IF, ELSE IF and ELSE

Theo Okelola
Jul 23, 2017 · 1 min read

Writing code can be very tedious. I ran into a problem when I was trying to write a code that would display one thing if a statement was true and another if the statement was false. This is when I ran into the elseif command. If the expression is false, the inner block of an if-statement is not reached. The statements are not executed. For example, this is what it looks like in ruby:

# Two integers.
a = 1
b = 2

# Use if, elsif, else on the integers.
if a > b
# Not reached.
print "X"
elsif a == b
# Not reached.
print "Y"
else
# This is printed.
print "Z"
end

The if statement is how we create a branch in our program. The if statement includes a true-or-false expression. If that expression is equal to true, then ruby will execute the puts/prints statement that follows the if statement. However, if the expression is false, then ruby skips the puts/prints.

Did You Know???

Render Method

Theo Okelola

Written by

Did You Know???

Render Method

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade