Control Flow in Ruby
Learn how to write more complex programs that can respond to user input.
StartKey Concepts
Review core concepts you need to learn to master this subject
elsif
Statements in Ruby
Ruby not Operator
Else statement in Ruby.
Comparison operators in Ruby.
Or operator in Ruby.
if
Statement in Ruby
And operator in Ruby.
Unless statement in Ruby.
elsif
Statements in Ruby
elsif
Statements in Ruby
print "enter a number: "
num = gets.chomp
num = num.to_i;
if num == 5
print "number is 5"
elsif num == 10
print "number is 10"
elsif num == 11
print "number is 11"
else
print "number is something other than 5, 10, or 11"
end
In Ruby, an elsif
statement can be placed between if
and else
statements. It allows us to check for additional conditions.
More than one elsif
can be placed between if
and else
.
Control Flow in Ruby
Lesson 1 of 2