Nodes/ComfyUI_Lam/计次内循环首
ComfyUI Node

计次内循环首

The patched, in-process loop head with a data backhaul

By yanlang0123·Created 2 years ago·Updated 11 days ago· 77
计次内循环首
    • DOWHILE
    • 循环次数
    • seed
    • 回传数据
    • 总数
    • 步长
    total0
    stop1
    i0

    ForInnerStart (计次内循环首) opens the pack's inner counted loop - the one that runs inside a single ComfyUI execution instead of re-queueing the graph every iteration like the older ForStart/ForEnd pair. Same counter idea (total, step, current index), but it runs in-process, carries data back around the loop, and pairs with ForInnerEnd, which collects every iteration's result into one batch.

    "内循环" translates to "inner loop." Think of it as the loop you use when the loop is part of a larger workflow rather than the whole workflow - a refinement pass inside a bigger pipeline, not the top-level "render these 20 images" driver.

    How it works

    At a glance it looks like ForStart: you set total, stop and the starting i, and you get back the total, the iteration count, and a per-iteration seed. The difference is the backhaul. This start node accepts returned data from the loop's end and pushes it back into the next pass - so iteration N can see what iteration N-1 produced. That's what makes iterative refinement loops (denoise, check, refine again) possible inside one graph. Its DOWHILE output carries the loop token that ForInnerEnd uses to identify the loop.

    And the catch, again: this family lives on the author's patch to ComfyUI's execution.py. The start node on its own is just a counter; the loop control is patched into the executor. No patch, no loop.

    The inputs and outputs

    • total (INT, 0–99999) - iteration count.
    • stop (INT, 1–999) - step size per pass.
    • i (INT, 0–99999) - starting index.

    Outputs worth knowing:

    • DOWHILE - the loop token; wire to ForInnerEnd's start.
    • 循环次数 (INT) - current iteration.
    • seed (INT) - deterministic per-iteration seed, seeded from the index.
    • 回传数据 (*) - the data returned from the previous pass (the backhaul).
    • 总数 / 步长 (INT) - total and step, passed through for convenience.

    Install

    Standard pack install:

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

    then restart and apply the execution.py patch (修改文件.bat / .sh in the repo) - this node's loop behavior depends on it. Re-apply after every ComfyUI update; core updates overwrite the patch and the loop silently degrades into errors.

    Common issues

    • Loop body doesn't repeat - the patch is missing or was overwritten by an update. Re-run it.
    • Previous pass's data not visible - the backhaul needs ForInnerEnd feeding its result back into the loop; check that obj returns on every iteration, not just the last.
    • Counts but only the last result survives - you're reading endObj on the end node instead of the accumulated objs. Both exist; grab the right one.

    If you don't need iteration-to-iteration data, the plain ForStart/ForEnd pair avoids the patch entirely. If you do - if the loop is a refinement loop - this is the one.

    Categorylam

    Inputs (3)

    NameTypeDefaultDescription
    totalINT00–99999
    stopINT11–999
    iINT00–99999

    Outputs (6)

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