Profile

Choih0401 Story

Choih0401

5. 조건문(Conditionals) - Lua(루아)

5. 조건문 (Conditionals)


if else 조건문


if ~then -- ~하면

A       -- A 하고


else -- 아니면


B -- B 해라


end


난수를 이용해 홀수이면 홀수를 출력하면 짝수를 출력하는 예제


math.randomseed(os.time())

local rnd = math.random(1, 100)

if rnd % 2 == 0 then

print(rnd .. ": 짝수")

else

print(rnd .. ": 홀수")

end

math.randomseed(os.time()) 항상 같은 난수가 나오지 않게 하기 위해 시간을 대입하여 매번 다른 값이 나오도록 초기화해주는 것입니다.

'Corona with Lua > Lua language' 카테고리의 다른 글

6. 반복문 (Loop) - Lua(루아)  (0) 2018.03.09
4. 연산자 (Operator) - Lua(루아)  (0) 2018.03.09
3. 타입 (Type) - Lua(루아)  (0) 2018.03.09
2. 변수 (Variable) - Lua(루아)  (0) 2018.03.09
1. 기초지식 - Lua(루아)  (0) 2018.03.09