zoukankan      html  css  js  c++  java
  • 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," "}
    

      

  • 相关阅读:
    LeetCode 225. 用队列实现栈 做题笔记
    杨辉三角
    字母图形
    01字符串
    圆的面积
    饮料和啤酒
    进制转换
    从今天起 复习算法
    乘法群
    Paillier同态加密的介绍以及c++实现
  • 原文地址:https://www.cnblogs.com/xiaoliu66007/p/3611882.html
Copyright © 2011-2022 走看看