「Lua」ネスト構造if文を使うサンプル

環境
Lua 5.4.4

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if 条件1 then
if 条件2 then
処理コード
if 条件1 then if 条件2 then 処理コード
if 条件1 then 
   if 条件2 then
   処理コード

if文の中にif文を記述しています。ネストの構造です。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
x= 8
y = 8
if x == 8 then
if y == 8 then
print("8")
end
end
x= 8 y = 8 if x == 8 then if y == 8 then print("8") end end
x= 8
y = 8

if x == 8 then
      if y == 8 then
            print("8") 
      end
end

実行結果
C:\study\lua>lua 11.lua
8

Lua

Posted by arkgame