Skip to main content
This example demonstrates building workflows with conditional logic using CrystalFlow’s built-in IfNode and SwitchNode.

Overview

Conditional workflows enable:
  1. Branch execution based on runtime conditions
  2. Skip nodes when conditions aren’t met
  3. Dynamic path selection based on values
  4. Multi-way routing with switch/case logic

Basic If/Else Flow

The IfNode provides classic if/else conditional branching:

How It Works

  1. BooleanInputNode provides the condition value (true/false)
  2. IfNode receives the condition and optional data
  3. Based on condition:
    • true → Routes to thenOutput
    • false → Routes to elseOutput
  4. Only the active branch executes - the other is skipped
Only nodes connected to the active output execute. If condition is true, nodes on the else branch never run!

Numeric Comparison

Use comparison nodes to generate boolean conditions:

Available Comparison Operators

  • > - Greater than
  • >= - Greater than or equal
  • < - Less than
  • <= - Less than or equal
  • == - Equal
  • != - Not equal

Switch/Case Routing

The SwitchNode provides multi-way branching:

Dynamic Outputs

SwitchNode generates outputs dynamically based on the cases property:
  • 3 cases → 4 outputs: case_0, case_1, case_2, default
  • Add case → new output appears automatically
  • Remove case → output disappears

Nested Conditionals

Conditional nodes can be nested for complex decision trees:

If Inside If

Switch Inside If

Advanced Patterns

Multi-Stage Validation

Validate data through multiple conditional checks:

State Machine

Implement state transitions with switch:

React Component Example

Try It Yourself

The CrystalFlow examples package includes a complete ConditionalNodesDemo.tsx with:
  • All logic test nodes (CompareNode, IsPositiveNode, IsEvenNode, etc.)
  • IfNode and SwitchNode from @crystalflow/core
  • 7 documented workflow scenarios
  • Full interactive UI with property panel for configuring cases
Run the examples:

Key Concepts

Branch Evaluation

evaluateCondition() determines which branch executes at runtime

Single Branch Execution

Only the active branch runs - others are completely skipped

Dynamic Outputs

SwitchNode outputs update automatically when cases change

Nested Conditionals

Conditionals can be nested arbitrarily deep for complex logic

Next Steps

Conditional Flow Guide

Deep dive into conditional flow architecture

Built-in Nodes API

Complete IfNode and SwitchNode API reference

Creating Custom Nodes

Build your own conditional nodes

Data Processing

More workflow examples