Midio docs
  • Getting Started
    • Welcome
    • Quick Start Guide
  • Your First Midio App
  • Guides
    • HTTP
      • Making HTTP Requests
      • Responding to HTTP Requests
      • How to reach your own endpoints
      • CORS
      • Server-Sent Events (SSE)
    • Branching
    • Loops
    • Map, filter, reduce
    • Working with Data
    • Expressions
    • Building Agents
      • Streaming Agent API (experimental)
    • Debugging
    • Secrets and Environment variables
    • Convert JSON to data nodes
    • Writing tests
    • Cleaning up your flows
  • Package Manager
  • Integrating with third party services
  • Troubleshooting
  • Tutorials
    • Connecting LLMs to MCP-servers using the MCP-client package
    • Making Your Own MCP Server in Midio
    • A Fast Path to Functional RAG Agents
    • How to build a streaming agent using Server-Sent Events (SSE)
  • Reference
    • The Midio Editor
      • The Node Editor
      • User Traces
      • Traces (execution)
      • Processes
      • Log
      • Services
      • Problems
      • Function Signature
      • Data
      • Settings
    • The Midio Language
      • Nodes and execution
      • Functions and Events
        • Anonymous functions
      • Modules
      • Contexts
      • Data type
      • Local variables
      • Portals
      • Waypoint node
      • Partial function application
  • The Midio Engine
  • Built in Nodes
    • Core (std)
    • HTTP
    • LLM
Powered by GitBook
On this page
  • For
  • For Each

Was this helpful?

Edit on GitHub
  1. Guides

Loops

PreviousBranchingNextMap, filter, reduce

Last updated 2 months ago

Was this helpful?

Looping in Midio is as simple as connecting nodes in a loop. This can however easily create infinite loops if we don’t branch out of the loop at some point.

There are two main helper functions in Midio that makes it easy to prevent infinite loops:

  • - used to loop a given number of times

  • - used to loop once per item in a list

For

  1. Start the loop by triggering the reset input.

  2. Once all iterations are complete, the done output trigger is activated.

For Each

  1. Trigger the loop by activating the reset input.

  2. The item output provides the value of the current element, while the index output gives its position in the list.

  3. Once all items have been processed, the done output trigger is activated.

The node allows you to repeat a sequence of nodes a set number of times, determined by the iterations input.

will then activate the on count output trigger once per iteration, up to the specified number of times.

To continue looping, connect on count to the next node(s) in your sequence, and then back to the count input of . This advances to the next iteration.

The node allows you to loop through a list of items, executing a sequence of actions for each item in the list. Unlike a standard loop that runs a fixed number of times, automatically iterates over every element in a list, passing along both the current item and its index in the list.

For each item in the list, activates the on item output trigger.

For
For Each
For
For
For
For Each
For
For Each
For Each