Iterate
Summary
- Internal name:
Iterate - Category: Control Flow
- Purpose: Run a nested sub-workflow once per integer in a range, exposing the current value in a loop variable.
- Task type: Connector - see Tasks Overview > Connector Tasks for what this means before reading further.
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 (permissions depend entirely on whatever tasks are placed inside
"do")
- None (permissions depend entirely on whatever tasks are placed inside
Detailed description
The Iterate task is AndroMate's native for loop. It runs the sub-workflow embedded under its "do" key once for every integer from start_index to end_index inclusive, writing the current value into iteration_variable_input before each pass.
In the outer graph, Iterate behaves exactly like a normal task - one incoming link, one outgoing "to" link, followed once every pass of the loop has completed. All the repetition happens inside the task, not in the graph's Links.
The sub-workflow under "do" shares the same variable dictionary as the rest of the workflow: it can read any variable declared in the outer Start, and any output it produces (e.g. from a task inside the loop body) is visible to tasks that come after Iterate in the outer graph too.
Input parameters
| Parameter | Type | Required | Possible values | Android Compatibility | AndroMate Compatibility | Default |
|---|---|---|---|---|---|---|
iteration_variable_input |
String | Yes | A declared variable name starting with $ |
Android 13 (API 33) -> Android 16 (API 36) | 1.1.0 -> 1.1.0 | "" |
start_index |
Integer | No | Any integer | Android 13 (API 33) -> Android 16 (API 36) | 1.1.0 -> 1.1.0 | 0 |
end_index |
Integer | No | Any integer ≥ start_index to actually loop |
Android 13 (API 33) -> Android 16 (API 36) | 1.1.0 -> 1.1.0 | 0 |
do |
Object (sub-workflow) | Yes | A nested workflow object - see The do sub-workflow below |
Android 13 (API 33) -> Android 16 (API 36) | 1.1.0 -> 1.1.0 | - |
Output parameters
The Iterate task itself produces no outputs. Any variable written by a task inside "do" updates the shared workflow context normally, as if that task ran directly in the outer graph.
Exceptions
| Code | Exception Name | Description |
|---|---|---|
CONNECTOR-TASK-ERROR-001 |
No Sub Tasks | The "do" field is missing or empty - a connector task must contain a sub-workflow to run. |
Note: start_index > end_index is not an error - the loop simply runs zero times.
Execution flowchart
flowchart TD
Start([Iterate]) --> CheckDo{do sub-workflow\npresent?}
CheckDo -->|No| E1[CONNECTOR-TASK-ERROR-001\nNO_SUB_TASKS]
CheckDo -->|Yes| Loop[i = start_index]
Loop --> CheckRange{i <= end_index?}
CheckRange -->|No| Continue[Follow outer 'to' link]
CheckRange -->|Yes| SetVar[Set iteration_variable_input = i]
SetVar --> RunSub[Run do sub-workflow]
RunSub --> Increment[i = i + 1]
Increment --> CheckRange
Continue --> Success([VoidResult])
E1 --> Error([Exception])
style Start fill:#e3f2fd
style Success fill:#c8e6c9
style Error fill:#ffcdd2
style RunSub fill:#fff9c4
style SetVar fill:#c8e6c9
How it works:
- Check
do: raisesCONNECTOR-TASK-ERROR-001if the sub-workflow is missing or empty. - Loop: for
ifromstart_indextoend_indexinclusive: - writes
iintoiteration_variable_input, - runs the
"do"sub-workflow to completion (from itsStartSubTaskto itsEnd). - Continue: once every pass has run (or immediately, if
start_index > end_index), the engine follows the outer"to"link.
The do sub-workflow
do is a nested workflow object, structured like a normal workflow body but using StartSubTask instead of Start as its entry point:
"do": {
"StartSubTask": [{ "id": "10001" }],
"TextReport": [
{ "id": "10002", "texte": "Iteration number: $i", "texte_type": 0 }
],
"End": [{ "id": "10003" }],
"Links": [
{ "from": "10001", "to": "10002" },
{ "from": "10002", "to": "10003" }
]
}
StartSubTaskonly takes an"id"- novariables,Time_out, orexec_policy(those belong solely to the outer workflow's realStart).- Any task type may be used inside, including another
IterateorForEachElementfor nested loops. - All ids are increasing integers, never a string prefix. Number the outer workflow starting at
1000; number every"do"(at any depth) starting at10001, incrementing across every"do"in the same workflow rather than resetting - see Workflow Concepts > Nested Sub-Workflows for the full rule. - The sub-workflow's own
Links/Endare scoped to itself - they don't interact with the outer graph'sLinks.
Input parameter details
1. Input parameter: iteration_variable_input
The name of a declared variable that receives the current loop index (as a string) before each pass.
Example
Details
- Must start with
$and must already be declared in the outerStart.variables. - Read as a literal variable name - no resolution applied to this field itself (same convention as
SetAndromateVariable'svariable_input).
2. Input parameter: start_index / end_index
The inclusive integer range to loop over.
Example
Details
- Both optional - default to
0. - If
start_index > end_index, the loop body never runs (not an error).
Complete JSON example
Prints "Iteration number: 1" through "Iteration number: 5", using variable $i:
{
"Start": [
{ "id": "1000", "variables": [{ "variableName": "$i", "variableValue": "0", "is_kpi": false }] }
],
"Iterate": [
{
"id": "1001",
"title": "Print 1 to 5",
"iteration_variable_input": "$i",
"start_index": 1,
"end_index": 5,
"do": {
"StartSubTask": [{ "id": "10001" }],
"TextReport": [
{ "id": "10002", "texte": "Iteration number: $i", "texte_type": 0 }
],
"End": [{ "id": "10003" }],
"Links": [
{ "from": "10001", "to": "10002" },
{ "from": "10002", "to": "10003" }
]
}
}
],
"End": [{ "id": "1002" }],
"Links": [
{ "from": "1000", "to": "1001" },
{ "from": "1001", "to": "1002" }
]
}