• 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," "}
    

      

  • 相关阅读:
    hdu2089 不要62
    hdu4734 F(x)
    hdu3555 Bomb
    hdu3652 B-number
    hdu4352 XHXJ's LIS
    CodeForces 55D Beautiful numbers
    数位dp模板
    欧拉函数模板
    UVALive
    常用正则表达 (转)
  • 原文地址:https://www.cnblogs.com/xiaoliu66007/p/3611882.html
Copyright © 2020-2023  润新知