is pairs still necessary anymore because I see people and I’ve heard you can just do
for i,v in table do so i was wondering if it still has a use case
no
I can’t send that short of a post so technically you might be able to find some niche use case but in general you don’t need pairs or ipairs for iterating anymore
can’t really think of one for pairs, i know for ipairs you could use it to stop at nil indices when iterating over arrays
edit: btw anything that you can use pairs for you could just create your own custom iterator anyways
pairs is actually completely useless. It just exists as a legacy element. You can always just do:
for key, value in table do
-- bla bla bla
end
instead of using pairs. I recommend not using it.
man I can’t believe I’ve used it the whole time thinking it was necessary
Yeah, I did too actually! I used it for so long until I understood that it’s useless. It’s just a myth at this point that many scripting tutorial makers included for no reason because they themselves probably didn’t knew it was optional.
Or, get this, maybe they promoted using pairs() because it was literally (almost) required before like 2023???
There were different iterators like ipairs(), next, etc but pairs() was the most widely used one becasue it was able to be used for basically any kind of table
2023? I’m positive you could use it after 2022…
Before 2022, luaU was like lua in terms of iteration as it did not have any Generalized Iteration features. But, after 2022 luaU was modified to add Generalized Iteration.
So, pairs was required, neccessary, mandatory, before 2022. After that, not really. Most tutorials (after 2022) still use pairs!
For example: Lua Loops | What are they, and how do I use them?
Thank you for contradicting the following quotes from your prior message;
Time matters. Clearly, it’s a myth and included for no reason in todays era where Generalized Iteration is better than calling a function for iteration.
Before May 2022? Needed.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.