4
How to iterate with a table in Lua
?
Example:
dados = {
nome = 'Wallace',
idade = 25
}
4
How to iterate with a table in Lua
?
Example:
dados = {
nome = 'Wallace',
idade = 25
}
5
You can do it like this:
dados = {
nome = 'Wallace',
idade = 25
}
for k, v in pairs(dados) do
print(k, "=>", v)
end
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
I was seeing that there’s this one foreach
, foreachi
and foreachvar
. That’s in old versions?
Show me where you’re seeing this, I don’t know.
http://www.fabricadigital.com.br/media/Curso_Lua.pdf
Note that they are functions and not commands. The command is for
. The functions can be used, of course, they will receive Amble as parameters. The function semantics is a little different from the command, but it solves most situations well. In general I would avoid. This is almost the same as preferring jQuery to JS :)
Browser other questions tagged lua lua-table
You are not signed in. Login or sign up in order to post.
Now that you’re learning Moon, take a look at all the questions from tag, There are many things that have already been answered. Now that I have found this. And don’t forget to vote for all the good things you find in all the questions: http://answall.com/questions/tagged/lua?sort=votes&pageSize=50
– Maniero