zoukankan      html  css  js  c++  java
  • Ruby编程语言学习笔记4

    对应Ruby编程语言第五章

    #Ruby使用换行符、分号、then关键字 对条件表达式(expression)和后续内容(code)进行分割
    #
    if条件式
    =begin
    if expression 
      code
    end
    或者 if expression then code end 
    上边第一个我们用的是换行符,第二个我们用的是关键字then
    =end
    a=if 1==1 
      5 
     end
    puts a

    a=if 1==1 then 5 end
    puts a

    a=if 1==1;5 end
    puts a

    #作为修饰符的if
    #
    code if expression
    a=5 if 1==1
    puts a

    #unless条件式
    =begin
    #unless condition then code end
    或者
    unless expression 
      code
    end
    =end
    unless 1==2 then
      puts "unless condition"
    end

    a=unless 1==2
      4
    end
    puts a #4

    #作为修饰符的unless
    #
    code unless condition
    a=1 unless 1==2
    puts a #1

    #case条件式 
    x=1
    name=case
      when x==1 then "one"
      when x==2 then "two"
      else "many"
      end
    puts name #one

    name=case
      when x==1 
        "one"
      when x==2 
        "two"
      else "many"
      end

    puts name #one 

  • 相关阅读:
    codevs 1993草地排水
    欧拉筛板子
    约数和问题 (codevs2606 && 洛谷2424)
    排列组合
    Picture poj1177
    楼房 洛谷1382 && codevs2995
    洛谷P1027 Car的旅行路线
    codevs1020 孪生蜘蛛
    HDU1269 迷宫城堡
    洛谷P1078 文化之旅
  • 原文地址:https://www.cnblogs.com/jeriffe/p/2538378.html
Copyright © 2011-2022 走看看