ruby-condition judgment

Source: Internet
Author: User

=begin       conditional judgment statements include if statements, unless statements, case statements,=end#if  statements =beginif  conditions   then   processing 1elsif  conditions 2 then   processing 2else   processing 3end=enda = 10b =  20if a > b  puts  "A bigger than b" elsif a <  b  puts  "A smaller than b" else  puts  "a is equal  to b "endputs " a bigger than b " if a > b#unless  statement, In contrast to the IF statement, the condition is judged false when the processing =beginunless  condition is executed    processing 1else   processing 2end=enda = 10b =  20unless a > b  puts  "A smaller/same as than b" end# The case  statement, which applies to the comparison object, performs different processing depending on the value of the object, when it can specify multiple values at a time =begincase  compare object when  values 1 then    Handling 1when  Value 2 then   processing 2when  value 3 then   handling 3else   processing 4end= endtags = ["A",   " IMG ", " PRE "]tags.each do |word|  case word  when " P ", " A ",   "I",  "B",  "BLOCKQUOTE"     puts  "#{word} has child."   when  "IMG",  "BR"     puts  "#{word} has child."   else    puts  "#{word} cannoot be used"    Endendarray = ["a", 1, nil]array.each do |word|  case word   when String    puts  "The word is a string"    when numeric     puts  "The word is a numeric"    else    puts  "Other words are something"    endendtext.each_line do |line|  case line  when /^from:/i     puts  "Find a sender"   when /^to:/i    puts  "Find a receiver"   when  /^$/    puts  "Resolution are finnished"     exit   else    break  endend


This article is from the "Invite the Wind" blog, please be sure to keep this source http://yaoyuechengfeng.blog.51cto.com/2958475/1774804

ruby-condition judgment

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.