Iterator [LP]
Iterator [LP] — ComfyUI Node Guide
- index
ComfyUI doesn't have a real for-loop. There's no node that says "run this ten times, once per file in a folder." What the community does instead is a trick: you queue the same workflow multiple times, and use an INT widget's control_after_generate setting (right-click it, set it to "increment") to bump a counter by one on every run. Iterator is the small comparison node that makes that trick usable instead of just vibes-based.
What it does
It's a counter comparator. You give it the current index, a limit you're counting toward, and a mode - one of Greater, Less, Equal, Greater or Equal, or Less or Equal - and it hands the index straight back out. On its own that sounds pointless (why would you need a node that just returns the number you gave it?), but the point isn't the value, it's the comparison happening on the way through. This is the piece a hand-rolled loop reads to know "have I hit the end yet."
The whole "LevelPixel/Iterators" category in this pack - this node, GetIteratorDataImageFolders, GetIteratorDataVideos, ImageDataIterator - is built around the same idea: ComfyUI's queue is your loop, and these nodes give you the bookkeeping (current position, total count, stop condition) that a real loop would hand you for free in any other language.
Inputs and outputs
index(INT, default 0) - your current position. Typically wired from a primitive INT node set to increment each queue.limit(INT, default 0) - the count you're comparing against, usually "how many items am I processing."mode- which comparison you want: Greater, Less, Equal, Greater or Equal, Less or Equal.- Output:
index(INT) - the same value, passed through.
There's no boolean "done" output in the schema, so whatever downstream logic cares about the comparison result has to be wired to read it some other way in your graph - this node's job is the plumbing piece, not the whole stop-a-batch mechanism by itself.
How to actually use it
The pattern that makes this click: drop an INT primitive, right-click → convert the widget to the increment control, set it to start at 0. Wire that into index here, set limit to your item count (say, the image_count from GetIteratorDataImageFolders), pick a mode like "Less" so you know you're still inside range, and queue the prompt N times (ComfyUI's queue button has a "queue N times" option). Each run, your index climbs by one and this node is your reference point for where you are in the sequence.
Installing it
Grab it through ComfyUI Manager - search "ComfyUI-LevelPixel" (the pack shows up as "Level Pixel") and install. If you'd rather do it by hand: cd ComfyUI/custom_nodes && git clone https://github.com/LevelPixel/ComfyUI-LevelPixel.git, then restart ComfyUI. No models to download, no heavy Python dependencies for this one - it's a pure logic node, so if it's not showing up after install the usual culprit is just a restart that didn't happen, or ComfyUI Manager's "Update ALL" not having run yet.
Common issues
The main trap with anything in this "manual loop" family isn't Iterator itself, it's forgetting that ComfyUI doesn't automatically stop for you - if you queue 50 times and only have 20 items, you'll get 30 runs that don't do anything useful once your index runs past the data. Keep your queue count and your limit in sync, or better, read the count output from whichever GetIteratorData* node is feeding your loop so you're not hardcoding it by hand. And remember control_after_generate only increments after a run finishes - if you queue everything up front rather than one at a time, double check the order actually lines up with what you expect, since batched queuing behaves slightly differently than clicking Queue Prompt repeatedly.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| index | INT | 00–999999 | — |
| limit | INT | 00–999999 | — |
| mode | COMBO | Greater (index > limit) | 5 options: Greater (index > limit), Less (index < limit), Equal (index == limit), Greater or Equal (index >= limit), Less or Equal (index <= limit) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| index | INT | — |