Thanks this is really helpful because I was trying to make a shop system where you can press previous and next to move the camera and I made a table for every part in the folder(which isn’t really good) ipairs would be a good idea for this since it goes in order and when I tried to use regular pairs it didn’t go in order and indexing was a major part of it
I think there's another issue with using eye pairs if there is a gap in between The index values. For example, if there was only 1, 3 and 4. Also, I think there is an issue with "nil" as well.
That's not a issue it's just how it works if you have a table with the keys 1,2,3,5,6,7 the length of that table will be 3 and when you use ipairs it will loop upto 3 and no more but if you use pairs then the order might not be correct so only use ipairs if your table has no gaps in it
Ipairs only loops upto the table length So let's say you have a table with the keys 1,2,3,7,9 Ipairs will only go upto 3 because the length of the #table will be 3 Also ipairs loops in order But the order of pairs is undefined
well you can think of them as 2 types of iterations I'm just showing you how the other 2 work behind the hood. yes they behave differently the main one you need to be carful of is adding values to the table when using pairs as there is a chance it will iterate over the same key multiple times but its safe to remove values when using pairs
I kinder already did in the video next(workspace:GetChildren()) gets the first item in the linked list. When you use it in the for loop it works just like pairs
Many ppl don't really understand those, great you made a tutorial on them!
hopefully it help
@@5uphithe way you showed the array image really helped me personally that's the part I needed to “get over” thank you so much.
Thanks this is really helpful because I was trying to make a shop system where you can press previous and next to move the camera and I made a table for every part in the folder(which isn’t really good) ipairs would be a good idea for this since it goes in order and when I tried to use regular pairs it didn’t go in order and indexing was a major part of it
I knew this, but it is interesting to see how you explained it. Very great video!😄
"cake = yuck"
"broccoli = yummy"
bros caseoh's worst nightmare 💀
great vid but the audio bro i cant explain where i feel it, i feel it in my soul
thank you for this. i noticed that when i used pairs, it had a random index for strings and wondered why
ipairs
ipairs
ipairs
I think there's another issue with using eye pairs if there is a gap in between The index values. For example, if there was only 1, 3 and 4. Also, I think there is an issue with "nil" as well.
That's not a issue it's just how it works if you have a table with the keys 1,2,3,5,6,7 the length of that table will be 3 and when you use ipairs it will loop upto 3 and no more but if you use pairs then the order might not be correct so only use ipairs if your table has no gaps in it
@@5uphi ah, thanks so much for the clarification!
fast explaination of the whole vid:
ipairs goes in order while pairs dosen't
How did you research pairs and ipairs to gain your own understanding of it? Did you go thorough the documentation?
When I first started learning lua I first did a simple google to pairs vs ipairs but mainly understood them by simply using them
THE ORDA
roblox recently made it so the iterator isnt necessary, you can just do for i,v in myTbl do
Correct that is just like using pairs
How many years of experience you have?
So what change does it make? ipairs doesn't print strings or smthing
Ipairs only loops upto the table length
So let's say you have a table with the keys
1,2,3,7,9
Ipairs will only go upto 3 because the length of the #table will be 3
Also ipairs loops in order
But the order of pairs is undefined
@@5uphi Why is the length of the table till 3 only?
That's just how lua tables works because the key 4 is missing it only goes upto 3
@@5uphi Alr ty
No problem I'm sure there is a technical reason why lua did it like that but I don't know what lua is doing behind the scenes
what is the difference between using regular for loop and pairs loop?
It's equivalent to using pairs
Now i know this, thanks.
No problem
do this 4 different types of iteration behave differently if the lists are modified while iterating?
well you can think of them as 2 types of iterations I'm just showing you how the other 2 work behind the hood.
yes they behave differently
the main one you need to be carful of is adding values to the table when using pairs as there is a chance it will iterate over the same key multiple times but its safe to remove values when using pairs
hey can you also explain "next"? (ex. for i, v in next, workspace:GetChildren() do ....... end)
I kinder already did in the video next(workspace:GetChildren()) gets the first item in the linked list. When you use it in the for loop it works just like pairs
Can you tell where are those mostly use?
I am still confuse, like why use for loops?
If you look at my snake game video I talk about for loops in that video
with luau you don't even need either
yes you do
I don't know when I picked this up but I always use "for i, v in next, mytable do"
So far it works fine...Some people say I should use ipairs instead.
try to not take what others say seriously just do you
you're helpful on god