Control Flow

MDZ uses CAPS keywords for control flow to visually distinguish executable structure from prose content.

For Loop

Iterate over a collection using the collection operator (IN):

FOR $item IN $collection
  Process $item
  Next step
END

With Destructuring

Unpack tuples during iteration using destructuring:

FOR ($task, $priority) IN $items
  Execute $task
  IF $priority = "high" THEN
    Expedite processing
  END
END

Asynchronous Delegation

For parallel execution, use ASYNC DELEGATE inside a loop:

FOR $item IN $items
  ASYNC DELEGATE /process $item/ TO ~/agent/worker
END

Use ASYNC DELEGATE when:

  • Iterations are independent
  • Order doesn't matter
  • Maximum throughput is desired

While Loop

Loop with a condition. The DO keyword delimits the condition (like THEN for IF):

WHILE condition AND $iterations < 5 DO
  Perform iteration
  Update state
END

Condition Types

Conditions can be:

  • Deterministic condition: $x < 5, $status = "active"
  • Semantic condition: NOT diminishing returns (LLM interprets)
  • Combined: NOT complete AND $count < 10 (using logical operators)

Conditional

Branch with IF/THEN and optional else clause:

IF $condition THEN
  Do this
ELSE
  Do that
END

Multi-line Branches

IF $strategy = "accumulate" THEN
  Validate incrementally
  Update on success
  Log progress
ELSE
  Collect all candidates
  Validate at end
  Report summary
END

Comparison Operators

  • = — equality
  • != — inequality
  • <, > — less than, greater than
  • <=, >= — less/greater than or equal

Logical Operators

Use logical operators to combine conditions:

  • AND — both conditions must be true
  • OR — either condition can be true
  • NOT — negates a condition

Nesting

Control flow can be nested. Blocks are closed with END:

FOR $task IN $tasks
  Process $task
  IF $task.priority = "high" THEN
    WHILE NOT complete DO
      Execute step
      Check progress
    END
    Log completion
  END
  Move to next task
END

Break and Continue

Use BREAK and CONTINUE for early exit and skip within loops:

FOR $item IN $items
  IF $item.invalid THEN
    CONTINUE              # Skip to next iteration
  END
  IF $found = true THEN
    BREAK                 # Exit the loop
  END
  Process normally
END

BREAK and CONTINUE are valid in:

  • FOR loops
  • WHILE loops

They are not valid outside of loops (parser error).

Semantic Conditions

Semantic conditions are natural language expressions that the LLM interprets. Use them when the condition requires understanding context:

WHILE NOT diminishing returns DO
  Continue iterating
END

IF the result looks promising THEN
  Proceed with optimization
END

Composition Keywords

MDZ provides several keywords for composition:

DELEGATE (Agent Delegation)

Use DELEGATE to spawn autonomous subagent tasks:

DELEGATE /initial research/ TO ~/agent/explorer

USE (Skill Invocation)

Use USE to invoke a skill:

USE ~/skill/orchestrate TO /coordinate the workflow/

EXECUTE (Tool Execution)

Use EXECUTE to run an external tool:

EXECUTE ~/tool/browser TO /take screenshot/

GOTO (Section Navigation)

Use GOTO to jump to a section anchor:

GOTO #validation-prompt

See Composition for more details on these keywords.

Design Philosophy

  • CAPS Keywords — Visually distinct from prose
  • Explicit Termination — Always include bounds to prevent infinite loops
  • Mixed Conditions — Combine deterministic checks with semantic interpretation
  • Clear Indentation — Structure is visible at a glance
  • ASYNC DELEGATE — Enables concurrent execution
  • BREAK/CONTINUE — Enable early exit from loops
  • USE/EXECUTE/DELEGATE/GOTO — Composition keywords