(1.. - do |x| if 5) end
The use of the above flip-flop, you can be understood to be greater than or equal to 5 and less than or equal to 10 of the number printed out, that is understood as puts X if x >=5 && x <=10, but note you can not be written as follows
(1.. - do |x| if 5) end
If the code is written as a green background, it will cause the output to be greater than or equal to 5 or less than or equal to 20
Question 2 usage of flip-flop
Puts x if (x = = 5): (x = = Ten)
Not equivalent to puts X if x >=5 && x <=10 on normal judging conditions
def Test (a) if 5 Ten endtest (6)
The above code does not print out 6
def Test (a) if 5 Ten endtest (+) #不输出test (5) #输出5test (8) #不输出
But you pass in 5 and you can print out 5, but the other one doesn't print.
If you change to the following
def Test (a) if 5 Ten endtest (6)
is to print out 6 of the
Summary: Flip-flop usage is only within a block using rang, equivalent to >= && <= understanding
Ruby about flip-flop understand the last point of attention