#Learning Ruby chapter 3
#using conditional
x = 256
puts "1 x=256" if x == 256
if x == 256 then puts "2 x=256" end
if x == 256 : puts "3 x=256" end
x = true
y = false
if x and !y then puts "4 and == && =>true" end
if x && !y then puts "5 and == && =>true" end
if x or y then puts "6 or == || =>true" end
if x || y then puts "7 or == || =>true" end
if !y then puts "8 not == ! =>true" end
if not y then puts "9 not == ! =>true" end
#what is true / false?
somevariable = "whatever"
if somevariable then puts "10 everything is true" end
somevariable = nil
if somevariable then puts "11 except nil and false" end
#elsif
x = 5
if x == 0: puts "12 zero"
elsif x == 5: puts "12 five"
else puts "12 IDK"
end
#case / switch
puts case x
when 0...5 : "13 less then 5"
when 5...10 : "13 5<=x<10"
when 10..20 : "13 10<=x<=20"
else "13 IDK"
end
#while / until
print "14 "
i=0
begin
print i+=1
end while i < 3
while i < 6
print i+=1
end
print "\n15 "
i=0
print i+=1 until i > 5
puts
#other loops
print "16 "
for i in 1..6
print i
end
print "\n17 "
6.times{ |i| print i }
print "\n18 "
5.upto(9){ |i| print i }
print "\n19 "
9.downto(5){ |i| print i }
puts
#begin and end
BEGIN { puts "20 I AM FIRST!" }
END {puts "21 I AM LAST!" }