Skip to content

Break

Summary

  • Internal name: Break
  • Category: Control Flow
  • Purpose: Immediately stop the enclosing loop connector (Iterate, ForEachElement, or ForEachElementInScreen) - the outer workflow then continues normally right after the loop.
  • Task type: Normal

Compatibility

  • Minimum AndroMate version: 1.1.0

  • Maximum AndroMate version: 1.1.0

  • Minimum Android: Android 13 (API 33)

  • Maximum Android tested: Android 16 (API 36)

  • Supported manufacturers:

    • Samsung (One UI 6.x / 7.x / 8.x)
    • Other manufacturers - not supported yet (Xiaomi HyperOS and Google Pixel are being adapted)
  • Required permissions:

    • None

Detailed description

The Break task is AndroMate's equivalent of Java's break keyword. Placed inside the "do" sub-workflow of a loop connector (Iterate, ForEachElement, or ForEachElementInScreen), it stops that loop immediately: the current pass ends right there (any tasks placed after Break in the same "do" are skipped), no further iterations run, and execution resumes at whatever task follows the loop connector in the outer graph - exactly as if the range/list/element list had been fully consumed.

Break only makes sense inside a loop connector's "do" sub-workflow. It has no special meaning anywhere else in a workflow - see Exceptions below.

Break never takes an input and never produces a variable - it is a pure control-flow signal, usually placed behind a condition task's true branch (e.g. CompareStrings, CompareNumber, IsElementExist) so the loop only stops once a target has been found.


Input parameters

This task has no input parameters.


Output parameters

This task produces no output variable. It returns a VoidResult on success.


Exceptions

Code Exception Name Description
ITERATE-PIPELINE-007 Loop Break Requested Internal signal that stops the enclosing loop. Never visible when Break is used correctly inside a loop connector's "do" - only surfaces as an unhandled error if Break is placed outside any loop connector's sub-workflow (there is no loop there to catch it).

Execution flowchart

flowchart TD
    B([Break]) --> SetFlag[Request break on this do sub-workflow]
    SetFlag --> Return([VoidResult])
    Return -.->|next node check, same do| Check{Break requested?}
    Check -->|Yes| Throw[ITERATE-PIPELINE-007\nLOOP_BREAK_REQUESTED]
    Throw --> Catch[Caught by the enclosing\nloop connector]
    Catch --> StopLoop[Stop looping\nno further iterations]
    StopLoop --> Continue[Follow the loop connector's\nouter 'to' link]
    Continue --> Success([Outer workflow continues])

    style B fill:#e3f2fd
    style Success fill:#c8e6c9
    style Throw fill:#ffcdd2
    style SetFlag fill:#fff9c4
    style StopLoop fill:#fff9c4

How it works:

  1. Set the flag: Break requests a break on the TaskGraphControl attached to the "do" sub-workflow it runs inside, then returns VoidResult immediately - nothing is thrown at this point.
  2. Detected on the next check: right before executing the next node in that same "do" traversal, the engine notices the flag and raises LOOP_BREAK_REQUESTED - any task placed after Break in the same pass never runs.
  3. Caught by the loop: the enclosing loop connector (Iterate, ForEachElement, or ForEachElementInScreen) catches this specific signal, clears the flag, and stops looping - as if the range/list/element list had been fully consumed.
  4. Outer workflow continues: execution resumes normally at whatever task follows the loop connector in the outer graph.

Code examples

Example 1 - Stop a ForEachElementInScreen search once a target is found

"do": {
  "StartSubTask": [{ "id": "20001" }],
  "CompareStrings": [
    { "id": "20002", "var_x": "$elementText", "var_y": "Submit", "compare_type": "Equal" }
  ],
  "Break": [{ "id": "20003" }],
  "End": [{ "id": "20004" }],
  "Links": [
    { "from": "20001", "to": "20002" },
    { "from": "20002", "true": "20003", "false": "20004" },
    { "from": "20003", "to": "20004" }
  ]
}

Input parameter details

This task has no input parameters.


Output parameter details

This task has no output parameters.


Complete JSON example

Loops from 1 to 10, printing each number, but breaks out (without printing) as soon as $i reaches 5 - so it prints 1 through 4 only:

{
  "Start": [
    { "id": "1000", "variables": [{ "variableName": "$i", "variableValue": "0", "is_kpi": false }] }
  ],
  "Iterate": [
    {
      "id": "1001",
      "title": "Print until 5",
      "iteration_variable_input": "$i",
      "start_index": 1,
      "end_index": 10,
      "do": {
        "StartSubTask": [{ "id": "10001" }],
        "CompareNumber": [
          { "id": "10002", "num_x": "$i", "num_y": "5", "compare_type": 1 }
        ],
        "TextReport": [
          { "id": "10003", "texte": "Iteration number: $i", "texte_type": 0 }
        ],
        "Break": [{ "id": "10004" }],
        "End": [{ "id": "10005" }],
        "Links": [
          { "from": "10001", "to": "10002" },
          { "from": "10002", "true": "10004", "false": "10003" },
          { "from": "10003", "to": "10005" },
          { "from": "10004", "to": "10005" }
        ]
      }
    }
  ],
  "End": [{ "id": "1002" }],
  "Links": [
    { "from": "1000", "to": "1001" },
    { "from": "1001", "to": "1002" }
  ]
}