Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm not sure whether ipairs is in pairs?

Asked by 5 years ago

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 !

1 answer

Log in to vote
0
Answered by
SCP774 191
5 years ago
Edited 5 years ago

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!

Ad

Answer this question