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 

转载于:https://www.cnblogs.com/jeriffe/archive/2012/06/06/2538378.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值