For an example:
while true do x = x + 1 if x == 20 then --how do I make it stop? is there a special command??? nil????? end end
The while
loop will only loop again if the boolean expression supplied by the scripter evaluates to true
. The loop you provided in your question will run infinitely because true
will always evaluate to true
. You could replace the condition with one that is only true when x
is below a certain limit such as the one below:
while x <= 20 do x = x + 1 end
x <= 20
will only evaluate to true
when x
is less than or equal to 20.
Just check if the value is what you want every time the loop runs, that would look like this:
If x==20 then break end
Make sure to put it in the loop