【Lua】【流程控制】while
destination = 5 -- 終點位置
current_pos = 0 -- 目前位置
print([[馬拉松賽跑
============]])
print("終點位於:"..destination)
print("目前在:"..current_pos)
while current_pos < destination do
current_pos = current_pos + 1
print("往前跑1㎞,目前位於"..current_pos)
end
print("抵達終點,目前位於"..current_pos)
馬拉松賽跑
============
終點位於:5
目前在:0
往前跑1㎞,目前位於1
往前跑1㎞,目前位於2
往前跑1㎞,目前位於3
往前跑1㎞,目前位於4
往前跑1㎞,目前位於5
抵達終點,目前位於5