ComfyUI > Nodes > Basic data handling > switch/case

ComfyUI Node: switch/case

Class Name

Basic data handling: SwitchCase

Category
Basic/flow control
Author
StableLlama (Account age: 861days)
Extension
Basic data handling
Latest Updated
2026-05-07
Github Stars
0.04K

How to Install Basic data handling

Install this extension via the ComfyUI Manager by searching for Basic data handling
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter Basic data handling in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

switch/case Description

SwitchCase node enables dynamic path selection in workflows using an index-based mechanism.

switch/case:

The SwitchCase node is designed to facilitate decision-making processes within a workflow by implementing a switch/case selection mechanism. This node allows you to choose from multiple options based on a computed index, known as the selector. By providing a selector input, which is an integer, and multiple case value inputs, the node returns the value corresponding to the provided index. If the index is out of range, a default value is returned, ensuring that the workflow can handle unexpected or undefined cases gracefully. This functionality is particularly useful in scenarios where you need to dynamically select between different paths or outcomes based on varying conditions, enhancing the flexibility and robustness of your workflow.

switch/case Input Parameters:

select

The select parameter is an integer that determines which case value will be selected and returned by the node. It acts as an index to choose among the provided case values. The default value for select is 0, and it must be a non-negative integer. The value of select directly impacts the node's execution, as it dictates which case value is chosen. If the select value is within the range of available case indices, the corresponding case value is returned. If it is out of range, the node will attempt to return the default value if provided.

case_0

The case_0 parameter represents the first case value in the list of options. It can be of any data type, allowing for flexibility in the types of values you can handle. This parameter is marked as lazy, meaning it is only evaluated when needed, which can optimize performance in certain scenarios. The case_0 parameter is crucial as it serves as the initial option in the selection process, and its presence is required for the node to function correctly.

default

The default parameter is an optional input that provides a fallback value if the select index is out of range of the available case values. Like case_0, it can be of any data type and is also evaluated lazily. The default parameter ensures that the node can handle cases where the select index does not correspond to any defined case, thereby preventing errors and maintaining the continuity of the workflow.

switch/case Output Parameters:

result

The result parameter is the output of the SwitchCase node, representing the selected case value based on the select index. If the select index is valid and corresponds to a defined case value, the result will be that case value. If the select index is out of range, the result will be the default value if provided, or None if no default is specified. This output is crucial as it determines the path or outcome of the workflow based on the selection logic implemented by the node.

switch/case Usage Tips:

  • Ensure that the select parameter is within the range of defined case indices to avoid unexpected results and to ensure the correct case value is returned.
  • Always provide a default value to handle cases where the select index is out of range, which can prevent errors and ensure the workflow continues smoothly.
  • Utilize the lazy evaluation feature of the case_0 and default parameters to optimize performance, especially in complex workflows where not all cases need to be evaluated.

switch/case Common Errors and Solutions:

Selector Out of Range

  • Explanation: This error occurs when the select index is greater than the number of defined case values.
  • Solution: Ensure that the select index is within the range of available case indices or provide a default value to handle out-of-range selections.

Missing Default Value

  • Explanation: If the select index is out of range and no default value is provided, the node will return None.
  • Solution: Always provide a default value to ensure that the node can return a meaningful result even when the select index is out of range.

switch/case Related Nodes

Go back to the extension to check out more related nodes.
Basic data handling
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

switch/case