I understand what a for loop does but i cant seem to understand it, like what each part of the script does, most videos or explanations do not explain it properly to me, so can someone explain it, like i see this alot:
is a simple loop in Lua that runs once, setting the variable i to 1 and then immediately stopping. It’s similar to saying “once, I set a variable to 1.”
For loops use three values to control how many times they run: a control variable, an end value, and an increment value. Starting from the value of the control variable, the for loops will either count up or down each time it runs code inside the loop until it passes the end value. Positive increment values count up, negative increment values count down.
A for loop takes a either a table, or indices. And it’ll run until they’re done. If you do for i = 1,10 then it will do i=1, i=2, i=3… until it hits i=10.
But you can also make it take steps of 2, instead of steps of 1, by doing i = 1,10,2.
If you feed it a table, it’ll iterate over all the elements.
for - begins the loop
(any variable) = (multiplied by) - input 1 is our current number through the loop, and input 2 multiplies it.
(any number) - how many times it loops through.
— table loop
for - begins the loop
(any variable), (any variable) in pairs((any table)) - loops through the table, input 1 gives you how many times it has found something, input 2 gives you the current item of the table.
Plenty of people here that didn’t mind helping out. And a topic doesn’t just resolve 1 question: it can teach plenty of things, to many people. Gatekeeping isn’t the answer
You don’t understand, there is no gatekeeping going on here.
A simple google search could have answered this question more in depth and professionally.
If it were more of a complex question I’d understand, like; “should I use for i = 1, #Table do to get the amount of items or for i,v in pairs(Table) do?”
Not only that, when typing the function in the script editor, roblox gives you a straight up example of usage.