루비Ruby 제어문control statement

less than 1 minute read

if elsif else 구문 조건이 맞을 경우 실행 elif나 else if 가 아니고 어설프게 elsif이다

score = 10 if score > 100 then print “점수는 빵점에서 100점까지입니” elsif score > 90 then print score, “점 수 합격입니다” elsif score > 60 then print score, “점, 겨우 합격입니다” else print “불합격” end

unless 조건이 틀릴 경우 실행

score = 10 unless score > 60 then print “불합격” else print “합격” end

case 케이스에 맞는 경우 실행 숫자범위와 무자열비교 모두 가능

score = 10 case score when 0…60 then print “불합격” when 60…90 then print “그냥 합격” when 90..100 then print “우수 합격” else print “0부터 100까지의 숫자를 입력하세요” end

dep = “회계부” case dep when “경리부” then print “불합격” when “기획부” then print “그냥 합격” when “사업부” then print “우수 합격” else print “이 부서는 안됩니” end

ㅇㅇ