ruby学习--条件控制

条件控制

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

 

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

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 "\n next let`s look at *upto* method\n"
0.upto(2){|i| print i," "}
print "\n next let`s look at *downto* method\n"
2.downto(0){|i| print i," "}

  

 

posted @ 2014-03-19 17:18  君子笑而不语  阅读(136)  评论(0编辑  收藏  举报