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

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

CodersArts is a Product by Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram