all( tbl )
Returns an iterator for all non-nil items in a sequence in a table, for use with
The table to iterate.

The all() iterator function is used exclusively with to iterate over all elements in a sequence in a table. Each non-nil value in the sequence is emitted in sequence order.

Specifically, all() starts at index 1, then steps forward through the table until it reaches the final index, emitting only the elements which are not nil.

When used with a table that contains only unique elements, it is safe to delete the current loop iteration's element from the table. For instance, given a table of all whole numbers, it would be safe to iterate over it and delete prime numbers when they are found. However, in a table with duplicate entries, behavior is undefined and a different method should be used.

Examples Edit

t = {1, 3, nil, 5}
add(t, 7)
add(t, 9)
for v in all(t) do
  print(v)  -- prints 1, 3, 5, 7, 9
function no_primes(t)
  for e in all(t) do
    if is_prime(e) then
      del(t, e)

See also Edit

Community content is available under CC-BY-SA unless otherwise noted.