-
[Ruby] Conditionalscoding for food 2022. 7. 20. 13:22
num = 8
if num > 0
puts "positive"
end
if num % 2 = 0
puts "even"
end
조건이 두개 이므로 값이 두개가 나옴
----------------------------------------------------------------------
num = 8
if num > 0
puts "positive"
elsif num % 2 = 0
puts "even"
end
두갈래의 길 중에 첫번째 길 (if) 이 맞을 경우 결과값은 한개가 나온다.
if 가 아니면 elsif의 길을 갈수 있는 기회가 생김.
if is true, go down this path and print out positive. I don't even both checking this condition cause I arleady chose my path.
if-else-if 는 하나의 체인이기 때문에 둘중 하나만 선택할 수 있다.