Ruby about flip-flop understand the last point of attention

Source: Internet
Author: User


(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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.