首页 > 其他 > 详细

Ruby_day[1]控制流(if, unless)

时间:2014-10-22 21:37:10      阅读:242      评论:0      收藏:0      [点我收藏+]

summary:

  1: if, elsif, else.注意结束if时后面加end

  2: unless, else

 

  • How to use if, else, and elsif
  • How to use comparators / relational operators like ==(相等), !=(不等), <, <=, >, and >=

How to use boolean / logical operators like &&(与), ||(或), and !(非)

1 a = 10
2 b = 11
3 if a < b
4   print "a is less than b!"
5 elsif b > a
6   print "b is less than a!"
7 else
8   print "b is equal to a!"
9 end

 

1 problem = false
2 print "Good to go!" unless problem
3 #除非有问题(problem=true时不打出来),否则打印出来

 

多个逻辑运算结合,用括号 括起来

1 ( 1 == 1 ) && ( 2 == 2 )  // true
2 ( 1 == 2 ) || ( 2 == 2 ) // true
3 !( false ) // true

 

 

Ruby_day[1]控制流(if, unless)

原文:http://www.cnblogs.com/jypwn/p/4044231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!