「Lua入門」for文による繰り返しサンプル

環境
Lua 5.4.4
書式
for 初期値, 終了値, 増加量 do
処理コード
end
増加量は省略することができます.その場合,自動的に増加量は 1 となります.

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
for i = 2, 12, 3 do
print( i .. " test:abc")
end
for i = 2, 12, 3 do print( i .. " test:abc") end
for i = 2, 12, 3 do
 print( i .. " test:abc")
 end

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
C:\study\skill\lua>lua test.lua
2 test:abc
5 test:abc
8 test:abc
11 test:abc
C:\study\skill\lua>lua test.lua 2 test:abc 5 test:abc 8 test:abc 11 test:abc
C:\study\skill\lua>lua test.lua
2 test:abc
5 test:abc
8 test:abc
11 test:abc

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
for i = 9, 12, 1 do
print( i .. " test:abc")
end
for i = 9, 12, 1 do print( i .. " test:abc") end
for i = 9, 12, 1 do
 print( i .. " test:abc")
 end

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
C:\study\skill\lua>lua test.lua
9 test:abc
10 test:abc
11 test:abc
12 test:abc
C:\study\skill\lua>lua test.lua 9 test:abc 10 test:abc 11 test:abc 12 test:abc
C:\study\skill\lua>lua test.lua
9 test:abc
10 test:abc
11 test:abc
12 test:abc

 

Lua

Posted by arkgame