Skip to content

Instantly share code, notes, and snippets.

@edutrul
Created April 12, 2026 02:55
Show Gist options
  • Select an option

  • Save edutrul/6acfb2dfea8cfcd1e69122b6e07374e4 to your computer and use it in GitHub Desktop.

Select an option

Save edutrul/6acfb2dfea8cfcd1e69122b6e07374e4 to your computer and use it in GitHub Desktop.
For luau explained
local fruits = {"fruits", "apple", "orange"}
print(fruits[1])
for index, value in ipairs(fruits) do
print (index, value)
end
for index, value in pairs(fruits) do
print (index, value)
end
print('Example of a different object: with pairs')
local t = {
"red",
"blue",
name = "box"
}
for key, value in pairs(t) do
print(key, value)
end
print('vs ipairs')
for key, value in ipairs(t) do
print(key, value)
end
print('but in moderns luau many people use:')
for i, v in t do
print(i, v)
end
print('now if you dont want index then use _ which means ignore index')
for _, v in t do
print(v)
end
--[[
Running main.luau...
fruits
1 fruits
2 apple
3 orange
1 fruits
2 apple
3 orange
Example of a different object: with pairs
1 red
2 blue
name box
vs ipairs
1 red
2 blue
blue
but in moderns luau many people use:
1 red
2 blue
name box
now if you dont want index then use _ which means ignore index
red
blue
box
--]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment