Nodes/ComfyUI_Lam/计次循环首
ComfyUI Node

计次循环首

Total, step, and a seed that changes every pass

By yanlang0123·Created 2 years ago·Updated 11 days ago· 77
计次循环首
    • 总数
    • 循环次数
    • seed
    total0
    stop1
    i0

    ForStart (计次循环首) opens the pack's simplest loop: a counted loop with a step size. You tell it how many times to loop (total) and how big a step to take each pass (stop), and it hands you the current iteration index and a seed. Pair it with ForEnd and you've got "run this body N times" without a single condition to reason about.

    The display name means "counted loop head" - it's the bookend that starts the count, not the part that does work. The work happens between it and ForEnd.

    How it works

    ForStart is a counter with a side of reproducibility: it takes the current index i, and derives a random seed from it. Because the seed is a function of i, every pass through the loop gets a different but deterministic seed - run the loop twice and iteration 3 uses the same seed both times. That's exactly what you want when each pass is, say, a KSampler call and you need to vary generations across a batch while keeping each one re-runnable. The node outputs the total and the current index, so downstream nodes can log where they are or branch on progress.

    Note this is the simple, no-frills loop head. It outputs a plain count and seed - it doesn't carry arbitrary data around the loop like the inner-loop variant does. If your loop body needs to pass results between iterations, you want ForInnerStart instead.

    The inputs that matter

    • total (INT, default 0) - the number of iterations. This is the one you actually set.
    • stop (INT, default 1) - the step size per pass. 1 = every iteration; 2 = every other iteration (loop 1, 3, 5…).
    • i (INT, default 0) - the starting index. Leave 0 unless you're resuming or offsetting a loop.

    Outputs: 总数 (total), 循环次数 (the current index - despite the name it's the iteration counter), and seed.

    Install

    Same pack, same story:

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

    and restart. A genuinely useful detail: this old ForStart/ForEnd pair works through ComfyUI's queue API and does not require the execution.py patch that the pack's inner loops need. So if all you want is a counted loop, you can use this pair and skip the core patch entirely - a real point in its favor.

    Common issues

    • Loop never ends - check the ForEnd wiring: it needs both total and i from this node. If it's fed a stale i, it can loop forever or stop after one pass.
    • Every pass produces the same image - the body is using a fixed seed node instead of ForStart's seed output. Swap it.
    • Step feels wrong - remember stop is the step, not the number of iterations. total counts from i by stop.

    Simple, predictable, no condition to get wrong. For anything with an exit condition, graduate to the do-while pair.

    Categorylam

    Inputs (3)

    NameTypeDefaultDescription
    totalINT00–99999
    stopINT11–999
    iINT00–99999

    Outputs (3)

    NameTypeDescription
    总数INT
    循环次数INT
    seedINT