Nodes/ComfyUI_Lam/判断循环首
ComfyUI Node

判断循环首

The do-while loop opener that hands you a token, a counter and a seed

By yanlang0123·Created 2 years ago·Updated 11 days ago· 77
判断循环首
  • obj
  • DOWHILE
  • 循环次数
  • seed
  • 回传数据

DoWhileStart (判断循环首) is the entry point to the ComfyUI_Lam do-while loop: a loop that runs its body first and checks the exit condition afterward. In ComfyUI terms that means you build start → body → end, and the end node decides whether the body gets executed again.

It's the "start" half of a pair - the interesting one is actually DoWhileEnd, where the condition lives. This node's job is to open the loop, expose the loop's iteration counter and a per-iteration seed, and carry any data you pass it straight through to the body.

How it works

You drop it in, optionally feed it a starting object, and it emits a DOWHILE token - a special connection type that only the matching end node accepts. That token is how the graph knows which loop a DoWhileEnd belongs to. Every pass through the loop, the node also exposes how many iterations have run and a seed that's derived from the iteration count, so each pass can be given reproducible randomness rather than reusing the same seed every time. Whatever you feed in as obj rides along as 回传数据 ("return data") and comes back out, ready for the body to transform.

Like the pack's other loop internals (ForInnerStart/End), this one depends on the author's patch to ComfyUI's execution.py. The README's 修改文件.bat / 修改文件.sh apply it; without the patch, the loop machinery has nothing to hook into and the node family just doesn't execute properly.

The inputs and outputs

  • obj (*, optional) - data to carry into the loop. Images, text, whatever. It's optional, so a bare DoWhileStart with no input is fine as a counter-only loop.
  • DOWHILE - the loop token output. Wire this to your DoWhileEnd's start input.
  • 循环次数 (INT) - iteration count. Useful for logging, capping, or as a seed input to other nodes.
  • seed (INT) - a random seed regenerated per iteration (seeded from the count), so each pass of the loop can vary reproducibly.
  • 回传数据 (*) - the object you fed in, passed through untouched.

Install and the caveat that matters

Same pack install as always:

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

then restart, and - for this node specifically - apply the execution.py patch the README ships or the loop won't run. Re-apply it after every ComfyUI update; the patch lives in core and updates stomp it. It's the same patch that powers DoWhileEnd and the inner For loops, so it's a one-time setup that unlocks the whole loop family.

Common issues

  • "start" wire not connecting - you're feeding the DOWHILE token into the wrong slot, or a non-loop node's output. Only DoWhileStart's DOWHILE output belongs there.
  • Counter stuck at zero - you're reading 循环次数 from the start node but the loop body isn't feeding back into the end correctly, so the graph re-runs the start fresh each pass. Check the wiring between end and start.
  • Loop runs but nothing changes between passes - likely a seed that isn't actually varying, or the body reusing a fixed seed. Follow the per-iteration seed output rather than a global seed node.

If you never need a condition - just "run N times" - skip the do-while family entirely and use ForStart/ForEnd. Same patch requirement, fewer moving parts.

Categorylam

Inputs (1)

NameTypeDefaultDescription
objopt*

Outputs (4)

NameTypeDescription
DOWHILEDOWHILE
循环次数INT
seedINT
回传数据*