Both of the loops you mentioned in your post are used to iterate through all (not necessarily) elements of a table.
Let's say you've got a table like this:
myTable = {5, 4, 3, 2, 1}
If you wanted to execute some specific code on each element of the table, you would have to iterate through it. It can be done in a lot of ways, but let's first take the one easiest to understand:
for index = 1, #myTable, 1 do
outputChatBox(myTable[index])
end
What this code is, is basically a regular "for" loop, where the number of repetitions is determined by the length of the table. In this case,
#myTable
returns 5, so the code inside is executed 5 times, then it continues on something else. With each loop, the index variable gets increased by one, so you can then do
myTable[index]
in order to work with the values of the table.
So with each loop you can output one value of the table, or do any other stuff with it.
Now onto something slightly different, a for loop with an iterator:
for index, value in ipairs(myTable) do
outputChatBox(value)
end
This code should output exactly the same data as the earlier loop, but it uses different construct.
What this loop does, is automatically going through the entire table and with each repetition, it updates the index and value variables with current ones.
The value variable is going to be the same as myTable[index], but it is just more convenient because you don't have to read these values manually.
For further reading and some more examples I recommend you to go to http://www.phailed.me/2011/02/learn-lua ... ay-tables/ It explains the whole thing really great. If you think you've understand everything I was talking about, then it will be really easy for you to spot the obvious misconceptions and errors in your code, so you will be able to fix it yourself.