Examples
Conditional Flows

Conditional and Branching Flows Example

This example demonstrates how to implement conditional logic and branching in ZoopFlow to create dynamic workflows that adapt based on input data and runtime conditions.

What You'll Learn

  • How to implement if/else logic in flows
  • How to create dynamic branches based on conditions
  • How to use switch-case patterns for multiple conditions
  • How to implement loop constructs for repeated execution
  • How to combine conditional logic with error handling

Files in this Example

  • conditional-flow.ts - Demonstrates basic if/else conditional flow
  • switch-case-flow.ts - Shows implementing switch-case pattern for multiple branches
  • dynamic-branching.ts - Implements dynamic routing based on runtime data
  • loop-example.ts - Shows how to implement loop constructs
  • run-example.ts - Entry point to run the example

Conditional Flow Concepts

In ZoopFlow, conditional flows:

  • Allow dynamic paths of execution based on conditions
  • Enable complex business logic implementation
  • Support runtime decision making
  • Can branch to different steps based on input or computed values
  • Can express conditions using simple JavaScript expressions

How to Run

# From the project root
npm install
npx ts-node docs/new-structure/examples/conditional-flows/run-example.ts

Expected Output

The example will:

  1. Demonstrate a simple if/else branch based on input
  2. Show a switch-case pattern with multiple execution paths
  3. Implement dynamic branching based on runtime data
  4. Execute a loop construct until a condition is met

Output will show the different paths taken in each flow execution.

Next Steps

  • Create more complex conditional flows for real business logic
  • Combine conditional flows with error handling
  • Implement parallel execution with conditions
  • Explore integration with Temporal for durable conditional flows