1

# for i loops full explanation?

Edited 3 years ago

So basically im still confused on for i loops. All I know is that I can use it for mutiple part event using tables. Im familiar with this type of for i loop:

for i, some in pairs(something)


but not this :

for i = some - idk


So can anybody show me how to do it? If its just a simple explanation, im fine with that

1
Xapelize 2658
3 years ago
Edited 3 years ago

for loops are numeric loops, but ipairs loop is a loop which loop through table of instances

example

for number = 1, 5, 1 do
print(number)
end


output:

1
2
3
4
5


the first number in there is the minimum value, 1

second number is 5, which is the maximum value

you can think them as start and end

the third number is how many number skips per loop, default is 1, if you put something that is like for number = 1, 5, 6 do

it will not run, since it does not meet the requirement, formula is

(secondNumber - firstNumber) / thirdNumber = math.floor(howManyTimeItLoops)

for i, v in pairs / ipairs loop are instances loop like loop through an table of instances, well GetChildren returns a pair of table of the instance children, so we can do

for number, theChildrenThatIsDefinedOnLoop in ipairs(game.Workspace:GetChildren()) do
print(theChildrenThatIsDefinedOnLoop.Name .." is the ".. number .."st/nd/rd/th children"
end


it basically scans through children and print the currently scanning/ defined children value

if you dont understand, i think i will explain more since I HAVE HOMEWORK SO im in a candy rush moment byebye

0
oh by the way, pairs is randomly choosen children, so if you run my script (the ipairs part) with pairs, you will not get the same result everytime you run because its random (don't ask me why, i didn't make it) Xapelize 2658 — 3y
0
i have a hard time learning this too, but i hope i explained well because my logic isnt same with the other peoples (i think that's why i have a hard time learning this) Xapelize 2658 — 3y