Skip to content
Control Flow loopIndex

$loopIndex

Returns the zero-based index of the current iteration of the innermost loop ($for, $loop, $while, $jsonForEach).

Syntax

$loopIndex

Parameters

None.

Return value

  • 0, 1, 2… for the successive iterations.
  • Outside a loop, the error “Loop index outside a loop.” is raised.

Examples

$for[3]
Index $loopIndex
$endFor

Notes

  • $loopIteration and $i return the same value; $loopCount is one-based. See $for and $i.

Try it

Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.