Lua while循环错误。为什么我的while循环出现故障? [英] Lua while loops error. Why is my while loop malfunctioning?

查看:554
本文介绍了Lua while循环错误。为什么我的while循环出现故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一名新的lua程序员,我喜欢在lua中学习新东西。我正在学习:https://www.tutorialspoint.com/lua/lua_loops.htm但是,当我练习我的代码时它不会工作。在我的代码中,我定义了一个名为FolderImBalanced的对象,并将该对象设置为TRUE。稍后在代码中我将对象更改为FALSE。但是代码不起作用。怎么样?



As a new lua programmer i am enjoying learning new things in lua. I am learning from: https://www.tutorialspoint.com/lua/lua_loops.htm However, when i practice my code it wont work. In my code i defined a object called "FolderImBalanced" and make that object to TRUE. Later on in the code i changed the object to FALSE. But the code is not working. How come?

GetServerStats,UserImbalance = "Lua Server Status","Inbalance Pulsle"
print(UserImbalance)
FolderImBalanced,NewNilValue = true,false
while (true)
do
FolderImBalanced = false
end
print(FolderImBalanced)





我尝试了什么:



我尝试了一切。首先,我去了一个名为Stack Overflow的网站,并问了同样的问题。我得到的最好的回答是这个



What I have tried:

I tried everything. First i went to a site called "Stack Overflow" and asked this same question. The best reply i got was this "

Quote:

你编写的代码正在运行,即使它可能没有按照你的预期去做。现在,你的while循环无限期地执行。

The code you written is working, even though it may not do what you expect it to do. Right now, your while loop is executed indefinitely.





他不在乎更好地解释他的意思,所以我仍然留在最后我最不明智的是,他的意思是什么?最糟糕的是,他仍然没有解释我的代码是行不通的。



接下来我去google了,谷歌说:



He did not care to explain better what he meant, so i still left at the end of the day confused. What does he mean my indefindly? And worst of all, he still did not explain my my code would not work.

Next i went to google, and google said:

Quote:

忘记初始化循环条件中使用的变量。记住第一次检查条件是在开始执行循环体之前。

To forget to initialize a variable that is used in the condition of the loop. Remember that the first time the condition is checked is before starting the execution of the body of the loop.



再次,没有帮助。我花了几个小时试图找到解决方案,但没有人所以我来到这个网站,希望得到一个回应。



然而,主持人是势利的我没有理由禁止我,所以我来到这里。


Which again, does not help. I spent hours trying to find a solution but nobody has it. So i came to this site, hoping for a responce.

However the moderators were snobby and banned me for no reason, so i came here.

推荐答案

你写了一个无限循环(循环运行永远)因为while条件总是。您可以轻松检查它是否运行以下代码:

You wrote an endless loop (a loop running forever) because the while condition is always true. You may easily check it running the following code:
GetServerStats, UserImbalance = "Lua Server Status", "Inbalance Pulsle"
print(UserImbalance)
FolderImBalanced, NewNilValue = true, false
while true do
  FolderImBalanced = false
  print("inside the loop")
end
print(FolderImBalanced)





为了退出循环,你必须,要么

  • 更改循环条件,例如
  • while FolderImBalanced do
      FolderImBalanced = false
    end
    





    • 使用 break 语句,例如

    • Or

      • Use the break statement, e.g.
      • while true do
          FolderImBalanced = false
          break -- this exits the loop
        end
        


        这篇关于Lua while循环错误。为什么我的while循环出现故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆