Nodes/WAS Node Suite v3/Condition Chain
ComfyUI Node Runs on cloud

Condition Chain

If / else if / else, the legible way

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Condition Chain
    • index
    • matched
    • count
    fallback0
    condition_afalse
    condition_bfalse
    condition_cfalse
    condition_dfalse
    condition_efalse
    condition_ffalse
    condition_gfalse
    condition_hfalse
    condition_ifalse
    condition_jfalse
    condition_kfalse
    condition_lfalse
    condition_mfalse
    condition_nfalse
    condition_ofalse
    condition_pfalse
    condition_qfalse
    condition_rfalse
    condition_sfalse
    condition_tfalse
    condition_ufalse
    condition_vfalse
    condition_wfalse
    condition_xfalse
    condition_yfalse
    condition_zfalse

    If you've ever wished ComfyUI had an if / else if / else, this is the closest thing it ships. Condition Chain tests its conditions in order and answers with the position of the first one that holds. That's a number, not a boolean - which is exactly the trick, because a number plugs straight into an index switch and turns "which condition fired first" into "which branch runs."

    Under WAS Suite/Logic/Boolean, it takes up to 26 boolean conditions (condition_a through condition_z) plus a fallback integer. Unconnected slots are skipped, so numbering always follows what's actually wired. The outputs:

    • index - the position of the first true condition, counting connected slots from 0. This is the number you wire into an index switch.
    • matched - true when a real condition held, false when the fallback answered. Useful if you need to distinguish "condition three fired" from "nothing matched."
    • count - how many conditions are connected.

    The canonical pairing: chain → index switch

    The pattern the node was built for is two nodes. Condition Chain's index goes into the index input of an Any Index Switch, and each of the switch's candidate slots holds one branch of your logic:

    • condition_a true → index 0 → the switch passes input_a (your first if branch)
    • condition_b true → index 1 → input_b (your first else if)
    • …and so on down the ladder.
    • Nothing holds → the chain returns fallback. Set it to -1 and it also sets matched false, and a negative index on the switch reads as its last slot - reserve that last slot for your else case and the whole thing reads like a structured program.

    Why do it this way instead of a pile of chained gates? Readability. Two nodes with named slots and a numbered ladder is far easier to trace than five nested gates, and because each condition is tested in order with short-circuiting semantics - the first true one wins, the rest never matter - you get deterministic priority for free. If several conditions are true at once, the earliest one in the chain decides, every time.

    A genuinely useful concrete case

    A prompt router is the classic build. Condition A: the image is portrait orientation → feed the portrait prompt. Condition B: landscape → the landscape prompt. Condition C: square → square crop prompt. Else → the generic prompt. Or a model selector: "if steps > 30 and CFG high → slow quality checkpoint; else if the video input has audio → audio-capable checkpoint; else → the fast one." Each condition is a Compare Any feeding a condition socket; the chain picks the first that fires; the index switch hands you the right pipeline. And only the winning branch evaluates, so the losers' loaders don't even run.

    The one trap

    The fallback defaults to 0, which means "nothing matched" quietly behaves exactly like "condition_a matched" unless you set it deliberately. That silent conflation is the classic source of "why is my else branch doing the if branch's job?" - if your graph has a real else case, set fallback to -1 and read matched, or wire the fallback to a dedicated slot you keep empty for "none." Otherwise a chain with no matching condition routes to slot 0 and looks like a successful match.

    Installing

    Part of WAS Node Suite v3 (WASasquatch/was-node-suite-comfyui), WASasquatch's MIT pack - going since 2023, one of the ecosystem's long-standing essentials. Logic nodes carry no dependencies at all: no pip packages, no weights, nothing to configure. Requires ComfyUI 0.14.0+ since the v3 suite targets ComfyUI's newer node backend.

    Via ComfyUI Manager, search WAS Node Suite v3, or clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/WASasquatch/was-node-suite-comfyui
    

    Restart ComfyUI and it appears under WAS Suite/Logic/Boolean. Not in the menu after a fresh install? Your ComfyUI is older than 0.14.0 - update it and the pack's nodes register.

    CategoryWAS Suite/Logic/Boolean

    Inputs (27)

    NameTypeDefaultDescription
    fallbackINT0-1–25Answer when no condition holds; this is the `else`. -1 answers -1 and sets matched to false, which an index switch reads as its last slot.
    condition_aoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_boptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_coptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_doptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_eoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_foptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_goptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_hoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_ioptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_joptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_koptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_loptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_moptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_noptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_ooptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_poptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_qoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_roptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_soptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_toptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_uoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_voptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_woptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_xoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_yoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.
    condition_zoptBOOLEANfalseOne condition, `true` or `false`, tested in slot order. The first `true` decides the answer. An unconnected slot is skipped, so the numbering follows what is wired.

    Outputs (3)

    NameTypeDescription
    indexINTPosition of the first true condition, counting connected slots from 0, or the fallback when none held.
    matchedBOOLEANtrue when a condition held, false when the fallback answered.
    countINTConnected conditions. The index runs 0..count-1.