I'm trying somethings out and I've come across loops. I don't understand it and would really appriciate a explaination. Try not to give me a link to a video or something.
A numerical for
loop iterates through numbers at an interval. For example,
for i=1,10 do print(i) end
will print out 1 through 10. The default interval is 1.
for i=10,1,-1 do print(i) end
will print out 10 through 1, where the interval is -1.
A while
loop will evaluate a condition and repeat the code inside the loop while the condition holds true.
A repeat
loop will initially run the code inside the loop once, and repeat so long as the condition holds true. This is the same as a while loop except for the fact that it always runs through the loop once.
A generic for
loop uses return values from a function, like pairs
, ipairs
, next
, gmatch
, or any other function that is meant to be used in a generic for loop. You can get a more detailed explanation of generic for here.