ruby学习--条件控制

条件控制

本人喜欢用程序demo记录的方式来记录某方法的使用,如times方法,仅作个人学习记录

#--------------if语句(相反是unless)而while相同于until--------------
print "--------------if------------------------
ps: in ruby,the symbol ','just works as plusing string
"

x = 0

if x==0 then end
p "x=0" if x==0
unless x!=0 then end
#-->here is the way to use until(while)
#begin
# ...
#end until (condition)

#--------------case语句------------------------
p "--------------case------------------------"
scale =8
  case scale
    when  1..5then p "low"
    when 6..10then p "high"
  else        p "default"
end  
  
p "--------------cycle------------------------" 
3.times{|i| print i," "}  
print "
 next let`s look at *upto* method
"
0.upto(2){|i| print i," "}
print "
 next let`s look at *downto* method
"
2.downto(0){|i| print i," "}

  

原文地址:https://www.cnblogs.com/xiaoliu66007/p/3611882.html