2 조건문 사용해서 출력하기

    조건문을 사용해 메시지를 출력해 보도록 하겠습니다. 워크스페이스에 스크립트를 추가한 후 이름을 ‘ExampleIf ’로 변경합니다. 그리고 아래의 코드를 입력합니다.

     

    코드

    local color = "red"          -- color 변수에 "red" 저장
    
    if color == "red" then       -- if문 설정 조건1 - color 변수의 값이 "red"와 같으면 참
        print("Color is Red")    -- 조건1이 참이면 "Color is Red" 출력
    elseif color == "blue" then  -- elseif문 설정 조건2 - color 변수의 값이 "blue"와 같으면 참
        print("Color is Blue")   -- 조건2가 참이면 "Color is Blue" 출력
    else
        print("Is Not Color!!")  -- 조건1과 조건2가 모두 거짓이면 "Is Not Color!!" 출력
    end

     

    실행 결과

    Color Is Red

     

    여기서 color 변수의 값을 "blue"로 변경하고 실행하면 어떻게 될까요?

     

    코드

    local color = "blue"
        
    if color == "red" then
        print("Color is Red")
    elseif color == "blue" then
        print("Color is Blue")
    else
        print("Is Not Color!!")
    end
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.