ruby学习总结之-----条件判断

##########条件判断常用的3种:if、unless、case
###then可省略
if 条件1 then
   语句1
elsif 条件2 then
   语句2
else
   语句3
end

#####unless是与if完全相反地语句
unless 条件
   语句1
else
  语句2
end

#######then可以省略,可以进行值的比较,也可进行正则表达式的匹配,及判断对象是否为某类的实例。

case 想要比较的对象
when 值1
   语句1
when 值2
   语句2
end

你可能感兴趣的:(Ruby)