Mie Loop If Is Last ๐
Branch differently on the final iteration
- loop_ctx
- then_value
- else_value
- loop_ctx
- value
The mirror image of MieLoopIfIsFirst. MieLoopIfIsLast checks whether the loop is on its final pass and outputs one value if so, another if not.
Part of ComfyUI-MieNodes (ComfyUI_MieNodes), MieMieeeee's utility pack, under the ๐ Loop submenu.
Why you'd reach for it
Loops often need to do something special right at the end and nothing special before it: save the final result but not the intermediates, run a full-quality upscale only on the last pass, switch a prompt to a "finishing" variant, flip a flag that tells a downstream node to write out. This node is the clean way to say "only on the last iteration."
Note there's a subtlety: MieLoopStart already emits an is_last boolean, and MieLoopEnd's done fires on completion too. So why this node? Because IfIsLast does the branching for you - it selects between two values in one step rather than making you feed a raw boolean into a separate switch. If you just want the flag, use is_last; if you want "value A on the last pass, value B otherwise," use this.
The inputs and outputs that matter
loop_ctx(MIE_LOOP_CTX) - the loop context, which carries the position.then_value(any type, optional) - output on the final iteration.else_value(any type, optional) - output on every other iteration.
Outputs:
loop_ctx- passed through to keep the chain intact.value(any type) -then_valueon the last pass,else_valueotherwise.
Both inputs are the wildcard * type, so it switches images, latents, strings, numbers - anything - as long as both branches match what's downstream.
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 or heavy dependencies. Under ๐ MieNodes โ ๐ Loop.
Common issues
Don't confuse it with the finalize trigger. IfIsLast selects a value inside the loop body. It does not emit the collected batch - that's what the Finalize nodes do, gated on MieLoopEnd's done. Use IfIsLast for per-iteration branching, done for "the loop is over, hand me the results."
Both branches still compute. Like any ComfyUI switch, the node picks an output; it doesn't stop the unused branch's upstream from running. Don't hang expensive work off a branch expecting it to be skipped.
Mismatched types. The wildcard inputs won't catch it if then_value and else_value are different types - the consumer downstream will. Keep them the same.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| loop_ctx | MIE_LOOP_CTX | โ | |
| then_valueopt | * | โ | |
| else_valueopt | * | โ |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| loop_ctx | MIE_LOOP_CTX | โ |
| value | * | โ |