AIML Docs

Control Flow Elements

Elements for managing execution flow and conditional logic

Control Flow Elements

Control flow elements allow you to manage the execution flow and implement conditional logic in your workflows.

Available Elements

If

The <if> element enables conditional execution based on test conditions. Essential for branching logic.

ElseIf

The <elseif> element provides alternative conditions in an if/else chain.

Else

The <else> element provides a default execution path when no other conditions match.

ForEach

The <foreach> element enables iteration over arrays, processing collections of items.

Transition

The <transition> element defines state transitions, controlling workflow progression.

Common Use Cases

Conditional Logic

<if condition={({state}) => state.isValid}>
<transition target="success" />
</if>
<else>
<transition target="error" />
</else>

Data Processing

<foreach items={({state}) => state.data} var="item">
<llm>
  <prompt>
    {({item}) => `Processing: ${item}`}
  </prompt>
</llm>
</foreach>

State Management

<state id="processing">
<assign location="state.status" expr="active" />
<transition target="complete" />
</state>

Best Practices

  1. Flow Control

    • Use clear conditions
    • Handle all cases
    • Document complex flows
    • Consider error paths
  2. State Transitions

    • Define clear paths
    • Manage resources
    • Track state changes
  3. Iteration

    • Validate collections
    • Handle empty cases
    • Process efficiently
    • Monitor progress
  4. Error Handling

    • Provide fallbacks
    • Log issues
    • Clean up resources
    • Maintain consistency

See Also

On this page