Skip to content

i / j / k [terminology]

Terminology

Usage

  • Use for short-lived indices with no more specific role.
  • i is the primary index.
  • j is a secondary or nested index.
  • k is a third index or a write position when that role is obvious.
  • Prefer a semantic index such as w, r, mid, or idx when it carries meaningful algorithmic behavior.
for i in range(n):
    for j in range(i + 1, n):
        nums[i], nums[j] = nums[j], nums[i]