top of page

Ruby - if...else

File Name

rubyElseIf.rb

#!/usr/bin/ruby
marks = 90
if marks >= 90
   puts "Grade A+"
elsif marks >= 80
   puts "Grade A"
elsif marks >= 70
   puts "Grade B"
elsif marks >= 60
   puts "Grade C"
else
   puts "Pass"
end

How to run:

ruby rubyElseIf.rb


Output:

Grade A+


How to Use Multiple Conditions


You can do this by using the && (AND) operator:

if name == "David" && country == "India"
      #statement 1 -----------
      #statement 2 -----------
end

You can also use the || (OR) operator:

if age == 10 || age == 20
      #statement 1 -----------
      #statement 2 -----------
end

3 views0 comments

Recent Posts

See All
bottom of page