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:
- ✅ All manufacturers
-
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": "sub-0" }],
"TextReport": [
{ "id": "sub-1", "texte": "Iteration number: $i", "texte_type": 0 }
],
"End": [{ "id": "sub-100" }],
"Links": [
{ "from": "sub-0", "to": "sub-1" },
{ "from": "sub-1", "to": "sub-100" }
]
}
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. - Give sub-workflow ids a distinct pattern (e.g. a
sub-prefix) so they can never collide with ids in the outer graph. - 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": "0", "variables": [{ "variableName": "$i", "variableValue": "0", "is_kpi": false }] }
],
"Iterate": [
{
"id": "1",
"title": "Print 1 to 5",
"iteration_variable_input": "$i",
"start_index": 1,
"end_index": 5,
"do": {
"StartSubTask": [{ "id": "sub-0" }],
"TextReport": [
{ "id": "sub-1", "texte": "Iteration number: $i", "texte_type": 0 }
],
"End": [{ "id": "sub-100" }],
"Links": [
{ "from": "sub-0", "to": "sub-1" },
{ "from": "sub-1", "to": "sub-100" }
]
}
}
],
"End": [{ "id": "100" }],
"Links": [
{ "from": "0", "to": "1" },
{ "from": "1", "to": "100" }
]
}