Nodes/🐰 MaraScott Nodes/🐰 For Loop IntMathOperation - v1 /l
ComfyUI Node

🐰 For Loop IntMathOperation - v1 /l

The pocket calculator that makes loops count

By MaraScottΒ·Created 3 years agoΒ·Updated 10 months agoΒ· 179
🐰 For Loop IntMathOperation - v1 /l
    • INT
    β—„a0β–Ί
    β—„b0β–Ί
    β—„operationβ–Ύβ–Ί

    Sometimes you just need to add two integers. ComfyUI's core doesn't hand you an INT adder out of the box - the arithmetic lives in various utility packs - and this is the MaraScott loop set's answer: a bare a, b, and an operation dropdown that spits out an INT. Nothing fancy, which is exactly its charm.

    It's worth knowing because it's not only a general utility; it's a genuine load-bearing piece of the For Loop machinery. When you use For Loop Open/Close, the Close node internally builds this exact node to decrement the counter (remaining - 1) on every pass. So even if you never drag it onto a canvas yourself, it's running inside every loop you write.

    How it works

    Two INT inputs, one of six operations, one INT out:

    • add, subtract, multiply, divide, modulo, power.

    All plain integer math, no float precision surprises - divide is integer floor division, so 7 Γ· 2 gives 3, not 3.5. The result is a single INT output. That's the whole node.

    When you'd actually reach for it

    Inside a loop, it's the counter. Give it remaining on the a input, 1 on b, subtract, and feed the result back through a For Loop ToBoolNode to drive a while-style condition. Outside a loop it's just a handy inline calculator - e.g. computing a doubled latent size or a step count before it goes into a sampler, without adding a dependency-heavy math pack for one operation.

    It also makes a nice teaching node: it's the smallest example in the pack of how the loop's condition chain works, and reading its six-case if/elif is trivial.

    Installing it

    Ships in the MaraScott pack. ComfyUI Manager β†’ search "MaraScott" β†’ Install β†’ restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MaraScott/ComfyUI_MaraScott_Nodes
    

    Then restart. Yes, it's a one-node calculator in a pack that pins transformers==4.37.2 and installs opencv-python, numba and blend_modes - the utility is small but the install isn't. If you're already running the pack for AnyBus or the loops, this costs you nothing extra.

    Common issues

    Honestly, there's not much to break here. The one surprise is integer divide - if you expected 3.5 you'll get 3, so do any fractional work before or after, not with this node. And power can overflow into enormous INTs if you feed it big exponents; keep b sane. If you ever see a loop misbehaving around a counter, check whether the decrement is wired a = remaining, b = 1, subtract - getting a and b swapped is the classic mistake and it makes the counter count up instead of down.

    Category🐰 MaraScott/Loop/Logic

    Inputs (3)

    NameTypeDefaultDescription
    aINT0-18446744073709550000–18446744073709550000β€”
    bINT0-18446744073709550000–18446744073709550000β€”
    operationCOMBO6 options: add, subtract, multiply, divide, modulo, power

    Outputs (1)

    NameTypeDescription
    INTINTβ€”