Mie Loop End ๐
The node that actually makes the loop loop
- loop_ctx
- loop_ctx
- done
If MieLoopStart opens the loop, MieLoopEnd is what closes it and makes it repeat. This is the piece that does the actual work of iteration: you feed it the loop_ctx at the tail of your loop body, and it decides whether there's another pass to run or whether the sequence is finished. Without it, Start just runs your body once and calls it a day. With it, the body re-executes for every value in your list, range, or decrement schedule.
Part of ComfyUI-MieNodes (ComfyUI_MieNodes), MieMieeeee's utility pack, under the ๐ Loop submenu.
How it works
ComfyUI is a run-once DAG - it has no built-in concept of looping back. MieNodes fakes it by carrying loop state through the MIE_LOOP_CTX object and using End as the turnaround point. Every pass, End advances the loop's position. If there are iterations left, the body runs again with the next value; when the last one is done, End reports back and the graph moves on to whatever comes after.
That's why End is an output node - it sits at the terminal end of the loop and is what the executor keys on. You wire the loop_ctx coming out of your last body node into End's loop_ctx input, and that single connection is what completes the circuit.
The inputs and outputs that matter
The one required input is loop_ctx (MIE_LOOP_CTX) - the context threaded down from Start through all your body nodes. That's the connection that matters.
Two optional inputs:
state_json(default{}) - write key/values back into the loop's shared state at the end of each pass. This is how one iteration hands data to the next: stash a running total, a "best so far" score, a carried image reference. Downstream passes read it back with the ParamGet nodes.debug(default false) - flip on to print the loop's state each pass to the console. Genuinely useful when a loop is misbehaving and you can't see why.
Outputs:
loop_ctx- passed through, in case you want to chain more after End.done(BOOLEAN) - false while iterations remain, true on the final pass. This is the important one. It's the signal every Finalize node waits for - they only emit their collected batch oncedonegoes true. Wire it into your finalize step.
Installing it
ComfyUI Manager โ search ComfyUI-MieNodes โ install โ restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MieMieeeee/ComfyUI-MieNodes
then restart. No model downloads, no heavy dependencies for the loop nodes. Look under ๐ MieNodes โ ๐ Loop.
Common issues
The loop only runs once. Almost always the loop_ctx isn't actually reaching End - the chain got broken somewhere in the body, or you connected the wrong wire. Trace loop_ctx from Start, through every body node that passes it along, into End. It has to be one continuous thread.
My finalize node outputs nothing / an empty batch. Finalize nodes gate on done. If you didn't route End's done output into the Finalize node, it never fires. That single wire is the trigger.
I can't tell what state my loop has. Turn on debug. It dumps the state bag each pass so you can see exactly what's being carried and whether your state_json writes are landing.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| loop_ctx | MIE_LOOP_CTX | โ | |
| state_jsonopt | STRING | {} | โ |
| debugopt | BOOLEAN | false | โ |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| loop_ctx | MIE_LOOP_CTX | โ |
| done | BOOLEAN | โ |