조건문
조건문
if/else/elsif/end
if/else/elsif/endif x < y # Assumes x and y are defined
puts "x is less than y!"
elsif x > y
puts "x is greater than y!"
else
puts "x equals y!"
endexpression if booleanunless/else/end
unless/else/endunless hungry
# Write some
else
# Have some noms
endexpression unless booleancase/when/else/end
case/when/else/endcase language
when "JS"
puts "Websites!"
when "Python"
puts "Science!"
when "Ruby"
puts "Web apps!"
else
puts "I don't know!"
endcase language
when "JS" then puts "Websites!"
when "Python" then puts "Science!"
when "Ruby" then puts "Web apps!"
else puts "I don't know!"
endternary conditional expression
boolean ? Do this if true: Do this if falseputs 3 < 4 ? "3 is less than 4!" : "3 is not less than 4."Comparators
relational operator
==와=의 차이점
==는 같다는 표현으로 비교를 할 때 사용된다. =는 대입을 할 때 사용된다.
x = 2
y = 2
if x == y
print "x and y are equal!"
end!=: not equal<: less than<=: less than or equal to>: greater than>=: greater than or equal to
logical operator
&&: and (둘다 true 이면 true)||: or (둘중 하나만 true 이면 true)!: not (반대)
Last updated
Was this helpful?