我想知道是否可以使用for循环在同一行中多次添加文本。
前任:
while true do
for i = 1,3,1 do
local text = ("pending" + ("." * i))
print(text)
wait(1)
end
end
我知道这个例子是行不通的,但是我只是想知道是否还有另一种方式,而不是每次都检查变量i。
text
是,如果要在迭代之间预先设定其值,则不应在for循环中使用它。text
应该在while循环中位于本地。wait
函数。要重复点,请使用string.rep (str, number)
。..
。-- http://lua-users.org/lists/lua-l/2008-03/msg00212.html
function wait (seconds)
local start = os.time ()
repeat until os.time () > start + seconds
end
while true do
local text
for i = 1, 3 do
text = 'pending ' .. string.rep ('.', i)
print (text)
wait (1)
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句