Control Structures - Loops
Loops allow you to execute actions multiple times automatically, either by repeating an action or iterating over data.
In MacroDroid, there are two main types of loops:
1. Iterate Dictionary / Array
This loop goes through all elements of a dictionary or an array, executing the internal actions for each element.
Available Magic Text
Element value{iterator_value}
The value of the current element (works for both dictionaries and arrays).
Dictionary key{iterator_dictionary_key}
The current key. Only available for dictionaries.
Array index{iterator_array_index}
The current position (starts at 0). Only available for arrays.
Iteration number{loop_iteration}
The current loop counter.
- Starts at 1
- Increases with each repetition
- Also works inside this type of loop
2. Repetition Loops
These include general control flow loops:
- Repeat X times
- While loop
- Repeat until condition
- Repeat for a period of time
- Repeat until break (Until Break)
Available Magic Text
Current iteration{loop_iteration}
- Starts at 1
- Increases with each repetition
Loop Compatibility
{loop_iteration}works in all loops, including dictionary/array iterationiterator_*magic text only works in Iterate Dictionary / Array
Examples (Iterate Dictionary / Array)
Element {loop_iteration}: {iterator_value}Key: {iterator_dictionary_key} | Value: {iterator_value}Position {iterator_array_index} → {iterator_value}Iteration {loop_iteration} (index {iterator_array_index})
Important Notes
{iterator_value}→ element content{iterator_array_index}→ position (0-based){loop_iteration}→ loop counter (1-based)- You can freely combine all magic text within the same loop
