Nodes/ComfyUI_Lam/判断外循环首
ComfyUI Node

判断外循环首

The top of a do-while loop that ComfyUI never wanted

By yanlang0123·Created 2 years ago·Updated about a month ago· 76
判断外循环首
    • OUTDOWHILE
    • 循环次数
    • seed

    OutDoWhileStart ("判断外循环首", outer do-while start) is the head of a do-while loop - the kind of thing ComfyUI doesn't natively have. It's part of the ComfyUI_Lam loop family that lets you repeat a chunk of graph until a condition is false, then continue. If you've ever wanted to iterate a refinement pass until it "looks done," this is the machinery.

    But let's be honest about what this loop costs, because it's the most important thing in this article: these loop nodes only work if you patch ComfyUI's core execution.py. The pack's README is explicit - you run a "modify files" script (修改文件.bat / 修改文件.sh) that edits ComfyUI's own executor to make re-queuing mid-graph possible. That's a hack into the core, and it's the reason this loop exists at all: ComfyUI's executor is designed to run a graph once, and these nodes beat it into looping by re-invoking the executor from inside a node. Every ComfyUI update is a chance for the patch to break, and a broken core patch takes down everything, not just the loop nodes.

    What it actually does

    OutDoWhileStart produces a loop token (OUTDOWHILE) that pairs with OutDoWhileEnd, plus a 循环次数 (iteration count) that increments each pass, plus a seed derived from the count. That seed is a nice touch - it gives each iteration a deterministic but different seed, so repeated passes don't render identically. The loop body hangs between Start and End, and the End node re-triggers the Start until the loop condition (a value you feed it) goes falsy.

    The inputs and outputs

    Strictly, this node takes no required inputs in its schema - it's a generator.

    • Outputs: OUTDOWHILE (the loop token, wired to the matching End node), 循环次数 (iteration count, INT), seed (INT, varies per iteration).

    The node works with the pack's loop-body and End nodes as a set. You don't just drop Start in alone; it anchors the pair.

    Installing it

    From ComfyUI_Lam: Manager → "ComfyUI_Lam", or:

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

    Restart. Then the critical step: run the pack's file-modification script (修改文件.bat on Windows, 修改文件.sh on Linux) to patch execution.py, then restart again. Without that patch, the loop nodes silently misbehave or crash. Make a backup of execution.py before patching, and re-apply the patch after every ComfyUI update.

    Common issues

    The loop family is the pack's most fragile feature, and the failure modes are pack-wide: missing infinite-loop protection (if your condition never goes falsy, it loops forever - keep a max-iteration guard in the loop condition), the core patch breaking on updates, and the patch itself being a maintenance burden that a beginner should think twice about. The KB's take on the ecosystem is that dependency hell is already the default in ComfyUI; a node that edits execution.py is a whole additional class of breakage.

    If all you need is "repeat this N times," consider whether a batch/iteration approach avoids the core patch entirely - for many jobs it does, and it won't break your entire ComfyUI install on the next update. Use these loop nodes when you genuinely need conditional repetition, and back up execution.py first. Also: Chinese-language UI, near-zero community footprint, and on uninstall delete ComfyUI/web/extensions/lam to clear the leftover popup.

    Categorylam

    Inputs (0)

    No inputs

    Outputs (3)

    NameTypeDescription
    OUTDOWHILEOUTDOWHILE
    循环次数INT
    seedINT