After a coroutine finishes, its status becomes complete rather than suspended.

finished state Lua reports a completed coroutine as `dead`; this page models the final label without creating a thread object.

Completion Status

target
completion_status.lua
Replay: real traced execution (multi-file project)
local target = 3
local step = 0
local status = "suspended"

while step < target do
  step = step + 1
  status = "yielded"
end

if step == target then
  status = "dead"
end

print("target=" .. target)
print("step=" .. step)
print("status=" .. status)
local target = 1
local step = 0
local status = "suspended"

while step < target do
  step = step + 1
  status = "yielded"
end

if step == target then
  status = "dead"
end

print("target=" .. target)
print("step=" .. step)
print("status=" .. status)
local target = 2
local step = 0
local status = "suspended"

while step < target do
  step = step + 1
  status = "yielded"
end

if step == target then
  status = "dead"
end

print("target=" .. target)
print("step=" .. step)
print("status=" .. status)
  1. target ← 3, step ← 0, status ← suspended

    1local target→ 3 = 3 --@target=1, 22local step→ 0 = 03local status→ suspended = "suspended"
  2. step ← 1, status ← yielded

    pass 1 of 3
    5while step0 < target3 do6  step→ 1 = step + 17  status→ yielded = "yielded"8end
    All 3 passes — pass 1 is the card above
    passstepstatus
    10 1yielded
    21 2yielded
    32 3yielded
  3. status ← dead

    10if step3 == target3 then11  status→ dead = "dead"12end
  4. print("target=" .. target)

    14print("target=" .. target3)15print("step=" .. step3)16print("status=" .. statusdead)
    outputtarget=3
    step=3
    status=dead
  1. target ← 1, step ← 0, status ← suspended

    1local target→ 1 = 12local step→ 0 = 03local status→ suspended = "suspended"
  2. step ← 1, status ← yielded

    5while step0 < target1 do6  step→ 1 = step + 17  status→ yielded = "yielded"8end
  3. status ← dead

    10if step1 == target1 then11  status→ dead = "dead"12end
  4. print("target=" .. target)

    14print("target=" .. target1)15print("step=" .. step1)16print("status=" .. statusdead)
    outputtarget=1
    step=1
    status=dead
  1. target ← 2, step ← 0, status ← suspended

    1local target→ 2 = 22local step→ 0 = 03local status→ suspended = "suspended"
  2. step ← 1, status ← yielded

    pass 1 of 2
    5while step0 < target2 do6  step→ 1 = step + 17  status→ yielded = "yielded"8end
  3. step ← 2, status ← yielded

    pass 2 of 2
    5while step1 < target2 do6  step→ 2 = step + 17  status→ yielded = "yielded"8end
  4. status ← dead

    10if step2 == target2 then11  status→ dead = "dead"12end
  5. print("target=" .. target)

    14print("target=" .. target2)15print("step=" .. step2)16print("status=" .. statusdead)
    outputtarget=2
    step=2
    status=dead