Nodes/ComfyUI_MieNodes/Mie Loop If Is Last ๐Ÿ‘
ComfyUI Node

Mie Loop If Is Last ๐Ÿ‘

Branch differently on the final iteration

By MieMieeeeeยทCreated 2 years agoยทUpdated 28 days agoยท 225
Mie Loop If Is Last ๐Ÿ‘
  • 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_value on the last pass, else_value otherwise.

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.

Category๐Ÿ‘ MieNodes/๐Ÿ‘ Loop

Inputs (3)

NameTypeDefaultDescription
loop_ctxMIE_LOOP_CTXโ€”
then_valueopt*โ€”
else_valueopt*โ€”

Outputs (2)

NameTypeDescription
loop_ctxMIE_LOOP_CTXโ€”
value*โ€”