Skip to content

Foreach

Dennis Corvers edited this page Oct 23, 2026 · 1 revision

Enumerable:foreach

Calls a function once for each value in an iterable.

Syntax

values:foreach(action)

Parameters

Parameter Type Description
action function(value) Action performed for each value.

Returns

nil.

Remarks

The callback receives the value only. each and for_each are aliases. Use ipairs/pairs when the source iterator key is also needed.

Example

LuaQ.from({
    { name = "Ada", ready = true },
    { name = "Bryn", ready = false },
})
    :foreach(function(player)
        print(player.name .. (player.ready and " is ready" or " is preparing"))
    end)

See also

Ipairs · Pairs · Functions

Clone this wiki locally