Nodes/ComfyUI_Lam/判断循环尾
ComfyUI Node

判断循环尾

The condition-check end of the do-while loop that needs a patched ComfyUI

By yanlang0123·Created 2 years ago·Updated 11 days ago· 77
判断循环尾
  • start
  • ANY
  • obj
  • i
  • endObj

DoWhileEnd (判断循环尾) is the tail of the pack's do-while loop. The idea is dead simple: run the loop body, then check whether to go again - that's the "do" in do-while. You see this in normal code all the time; ComfyUI just doesn't have native loops, which is why this pack patches the engine to make them work (more on that below).

The pair is DoWhileStart → your workflow body → DoWhileEnd → back to DoWhileStart. The end node is where the condition actually gets evaluated and where the loop decides whether to re-enter the body.

How it works

DoWhileEnd takes the loop token from the start node, a condition value, and whatever data you want to carry through the iteration. If the condition is truthy, the body runs again; if it's falsy, the loop falls through and the end node hands you the final carried data. The i output is the iteration count - the first thing you'll want to look at when a loop misbehaves, because it tells you exactly how many times it ran.

The honest caveat: this is one of the pack's nodes that only works after you run the author's patch script (修改文件.bat on Windows, 修改文件.sh on Linux), which edits ComfyUI's own execution.py to give the loop nodes real in-process control over the graph execution. No patch, no working loop. And because it patches core ComfyUI, a ComfyUI update can silently wipe the patch and leave your loop workflow erroring in confusing ways.

The inputs and outputs that matter

  • start (DOWHILE) - wire this from the DoWhileStart node's loop token output. This is what identifies which loop you're closing.
  • ANY (*) - the condition. A boolean-ish value: truthy keeps looping, falsy stops. This is the one you'll actually wire with care.
  • obj (*) - data to carry through. Anything; images, strings, whatever the body produced.
  • Output i (INT) - how many iterations have run.
  • Output endObj (*) - the final carried data once the condition is false. Wire this onward, or into a print node to confirm what came out.

Install and the gotcha that actually bites

Install is the pack's usual one:

cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam

then restart. But for this family of nodes you must also apply the execution.py patch or the loop simply won't execute - the README's patch is a chunk of Python you paste into recursive_execute, and the .bat/.sh scripts do it for you. Test the patch on a throwaway install first if you can, and re-run it after every ComfyUI update. This is the fiddliest part of the whole pack, and it's exactly why people bail on these nodes: a loop is only worth it if you trust the engine beneath it.

Common issues

  • Loop never stops - the condition never goes falsy. Add a maximum-iteration guard if the pack's loop nodes support one, or wire the condition to include i.
  • "DoWhileEnd" errors after a ComfyUI update - the execution.py patch got overwritten. Re-run the patch script.
  • Nothing happens at all - wrong start token wired in, so the end node can't tell which loop it belongs to. Trace the DOWHILE wire.

If you just need a fixed number of iterations and no condition, use the pack's plain ForStart/ForEnd instead - same family, no condition to reason about.

Categorylam

Inputs (3)

NameTypeDefaultDescription
startDOWHILE
ANY*
obj*

Outputs (2)

NameTypeDescription
iINT
endObj*