Hi, after searching up in pairs
when I didn't know what it was in a generic for loop, I also came across ipairs
. I assume it's short for in pairs
but it doesn't seem to be right.
I hope someone can tell me whether ipairs
= in pairs
!
No. "ipairs" does not stand for "in pairs".
"ipairs" is a variant of "pairs" and other generic loop operators.
The differences between "ipairs" and "pairs" is that "ipairs" will automatically break when it encounters a "nil" value in a table while "pairs" doesn't.
Take the following scripts as example.
local MyTable = {"Hello!", "How are you?", nil, "Goodbye!"} for i,v in ipairs(MyTable) do print(v) end
Output:
Hello! How are you?
Now onto "pairs"
local MyTable = {"Hello!", "How are you?", nil, "Goodbye!"} for i,v in pairs(MyTable) do print(v) end
Output:
Hello! How are you? nil Goodbye!
Hopefully this helped!