This is what if-else-elsif statements look like in Ruby. Elsif means "Else If"
Example : Given Three positive numbers, a, b, c; are they sides of an isoceles, equilateral or scalene triangle ? Or do they not form a triangle at all ?
The Output is :
not a triangle
If you want to run it quickly, you could try it out in the Interactive Ruby Shell (irb) :
code if condition
5 /// 5
6 /// 5 + 1
6 /// 6
8 /// 6 + 2
"Unless" runs a code fragment if the conditional is false.
x = 10
unless x < 10
else unless x < 5
puts "Out of all unless statements"
Using case with numeric data :
More than three digits
Using Case with Strings :
More than four points, or a shape which we can't figure out
Check out some of our other Ruby Tutorials :
Computer Science >