summary:
1: if, elsif, else.注意结束if时后面加end
2: unless, else
- How to use
if
,else
, andelsif
- 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