im searched on google and youtube i cant find any answers so im asking here, how would you make a loop always change the numbers off something, like the number always going down, if the number is like 30 and i want it to go down by one and one?
COMMUNITY QUESTION
how do you make a while loop change numbers?
1 answer
To put it simple, you would want to change the value every time the while loop is executed. For example (on mobile, so you should tab it out, as I cannot):
local i = 30
print(i)
while i > 0 do
i = i - 1
print(i)
end
The while loop is a loop that simply checks if the value is true or not. So the while loop will make it print the following:
30 -- This prints out before the loop is executed. If it wasn't then the script would print out the following numbers twice (except 0).
29
28
27
-- Skipping ahead
3
2
1
0
The reason why it goes down to zero is because if "i" is still 1, the loop will continue. This is due to the fact that 1 is more than zero. The reason why it isn't more than or equal to, is because you would then get a -1 output as well.
You could input this code anywhere you'd need to. For example a function can be used and the value of "i" can be changed.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
thanks! this hleped alot!!