DEV Community

Cover image for Compound Logic in ruby
ZsmithWork777
ZsmithWork777

Posted on

Compound Logic in ruby

Compound logic in ruby

image you're grading a student's test.
Ruby will check multiple conditions one by oe.
using AND (&&) and OR (||) to decide the correct grade.

score = 85

Step one checks the first condition.

IS score greater than 90?
If yes, print "Excellent"

if score > 90
puts "Excellent"

Step 2: If the first condition fails,

# Ruby moves to the next line.

this time, it checks Two conditions together:

(score >= 80 AND(&&) score <90

puts "Good"

Both must be True to run for this to run.

elsif score >= 80 && score < 90
puts "Good"

Step 3: If the above also fails,

Ruby checks the next one:

(Score >= 70 OR(||) score == 60

puts " Average"

Steps 4: If nothing above is true,

Ruby executes the final "else" as a catch-all.

else
puts "Fail"
end

Top comments (0)