Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)


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:
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.


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.
Posted
Updated 7-Nov-18 11:35am

1 solution

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:
Lua
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)


In order to exit the loop, you have to, either
  • Change the loop condition, e.g.
Lua
while FolderImBalanced do
  FolderImBalanced = false
end

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900