1、 if语句
else if 简写成elsif
if sum > 1000
puts "big"
elsif sum >500
puts "medium"
else
puts "small"
end
2、三元运算
x = 5
puts x > 3 ? "bigger":"smaller"
3、case语句
name = "kaka"
case name
while "tony"
puts "hello tony"
while "mike"
puts "hello mike"
else
puts "hi#{name}"
end
4、while、loop、until,next and break
x = 0
while x < 10
x += 1
next if x%2 == 0
print x,"\n"
end
x = 0
loop do
x += 1
break if x >10
end
x = 0
x += 1 until x > 10
puts x # x => 11
在ruby中,只有false或者nil为假,其它都为真