=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