조건문

조건문

if/else/elsif/end

if 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!"
end
expression if boolean

unless/else/end

unless hungry
  # Write some 
else
  # Have some noms
end
expression unless boolean

case/when/else/end

ternary conditional expression

Comparators

relational operator

  • === 의 차이점

    ==는 같다는 표현으로 비교를 할 때 사용된다. =는 대입을 할 때 사용된다.

  • != : 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?