while loop
. While there isn't a problem with it, the way most people use it, does result in issues. Here is the typical useage:
while true do
wait()
-- code
end
Now, that's fine and dandy, only that could create massive lag. Here is a better version:
while true do
wait(2)
-- code
end
The first example will run about 2,000 time a minute, while the second will only run 30 times a minute.
The next type of loop is called the
for do
loop. This loop will make it run a certain amount of times. Here is an example:for i=1,10 do
wait()
print(i)
end
This will print the numbers 1-10, then stop. There are many ways to use the
for do
but those are more advanced and I'll get to that in a later post.The final loop is the
repeat until
loop. This will repeat a piece of code until a criteria is met. Here is a simple example:x=10
y=0
repeat
y = y +1
wait(5)
until y == x
This will continue the loop until the value of y is the same as the value of x.
I hope this helped!
BCGames out! Remember to follow me on twitter! I'm @Zynnar!
No comments:
Post a Comment
Write your comment here... OR Flingi will eat you