Generic for loop

  • Loops using an iterator
  • The generic for loop traverses all values return by an iterator for a data structure
    • We will see more data structures to which this could apply in later sections
    • The function pairs returns the index and value of each element of a table in order

local tableDays = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} for k,v in pairs(tableDays) do print(k, v) end