Please note:
I know how to iterate a table, this question is basically asking how to iterate ALL content in a table. For example, if you have a table like: local t = {a = 1, b = {1,2,3}} , I'd want to return a table with all it's unpacked data, assuming there are nested tables in it. Like getting all descendants of an object, except instead of iterating an object, it'd be a table.
Question
I know how I could iterate all content in a table with recursive functions, but is there a way to do it with loops instead? This is my current code for my current table iteration:
local function tree(t)
local all = {}
local function add(x)
for i,v in next, x do
all[#all+1] = v
if type(v) == "table" then
add(v)
end
end
end
add(t)
return all
end
for i,v in next, tree{
a = 1,
b = {1,2,3}
} do print(i,v) end -- prints all values
But I'd like a looped alternative a lot more. If anyone knows how or if this is possible, I'd appreciate the explanation. Thanks.

3 comments
I know how to iterate a table. My question is asking how to iterate all values of a table, assuming there are nested tables inside of the one I'm iterating.
Edited.
your solution doesn't iterate past the first nested table. It should work with infinitely nested tables.