重复此操作,直到在lua中循环
我的lua代码有什么问题重复此操作,直到在lua中循环,lua,Lua,我的lua代码有什么问题 local which print("Type f to convert fahrenheit to celsius and c to convert celsius to fahrenheit") which = io.read() repeat if which=="f" then local c local f print("input your fahrenheit temperature")
local which
print("Type f to convert fahrenheit to celsius and c to convert celsius to fahrenheit")
which = io.read()
repeat
if which=="f" then
local c
local f
print("input your fahrenheit temperature")
f = tonumber(io.read())
c = (f-32)/1.8
print(c)
end
elseif which=="c" then
local ce
local fa
print("input your celsius temperature")
c = tonumber(io.read())
f = (c*1.8)+32
end
else do
print("Type f to convert fahrenhiet to celsius and c to convert celsius to fahrenheit")
until which=="f" or which=="c"
在
elseif
之前不应该有end
。在else
之前和之后都不应该有end
。在else
部分之后和部分之前应该有一个end
,直到:
repeat
if ... then
...
elseif ... then
...
else
...
end
until ...
下次,如果您至少发布问题所在(错误消息、意外输出等),这将非常有用。在elseif
之前不应该有end
。在else
之前和之后都不应该有end
。在else
部分之后和部分之前应该有一个end
,直到:
repeat
if ... then
...
elseif ... then
...
else
...
end
until ...
下次,如果您至少发布了问题所在(错误消息、意外输出等),这将非常有用。您首先关闭了if
块。删除用于关闭if
和elseif
的end
语句,并将其放在else
之后
local which
print("Type f to convert fahrenheit to celsius and c to convert celsius to fahrenheit")
which = io.read()
repeat
if which=="f" then
local c
local f
print("input your fahrenheit temperature")
f = tonumber(io.read())
c = (f-32)/1.8
print(c)
elseif which=="c" then
local ce
local fa
print("input your celsius temperature")
c = tonumber(io.read())
f = (c*1.8)+32
else
print("Type f to convert fahrenhiet to celsius and c to convert celsius to fahrenheit")
end
until which=="f" or which=="c"
p.S.:这可能会导致无限循环。您需要在重复中的每次迭代后更新,直到。您首先关闭if
块。删除用于关闭if
和elseif
的end
语句,并将其放在else
之后
local which
print("Type f to convert fahrenheit to celsius and c to convert celsius to fahrenheit")
which = io.read()
repeat
if which=="f" then
local c
local f
print("input your fahrenheit temperature")
f = tonumber(io.read())
c = (f-32)/1.8
print(c)
elseif which=="c" then
local ce
local fa
print("input your celsius temperature")
c = tonumber(io.read())
f = (c*1.8)+32
else
print("Type f to convert fahrenhiet to celsius and c to convert celsius to fahrenheit")
end
until which=="f" or which=="c"
local which
repeat
print("Type f to convert fahrenheit to celsius and c to convert celsius to fahrenheit")
which = io.read()
if which=="f" then
local c
local f
print("input your fahrenheit temperature")
f = tonumber(io.read())
c = (f-32)/1.8
print(c)
elseif which=="c" then
local c
local f
print("input your celsius temperature")
c = tonumber(io.read())
f = (c*1.8)+32
print(f)
end
print("do you want to play again? y/n?")
antwort = io.read()
until antwort ~= "y"
p.S.:这可能会导致无限循环。你需要在每次迭代之后更新,直到重复。保持一致的缩进可以让事情更清楚:缩进你的重复体。。。这将有助于您解决许多此类错误(虽然不完全是这种情况)。保持一致的缩进将使事情更加清楚:缩进重复正文。。。这将有助于您解决许多此类错误(虽然不完全是这种情况)。您能否非常简要地描述问题是什么?您能否非常简要地描述问题是什么?
local which
repeat
print("Type f to convert fahrenheit to celsius and c to convert celsius to fahrenheit")
which = io.read()
if which=="f" then
local c
local f
print("input your fahrenheit temperature")
f = tonumber(io.read())
c = (f-32)/1.8
print(c)
elseif which=="c" then
local c
local f
print("input your celsius temperature")
c = tonumber(io.read())
f = (c*1.8)+32
print(f)
end
print("do you want to play again? y/n?")
antwort = io.read()
until antwort ~= "y"