On the Wiki there is a detailed example of processing a file's content [External Link].
Tip: if you accidentally create a task that never ends when experimenting with loops, use the Kill button in the Task Edit screen to end it manually.
A condition consists of an operator ('equals' etc) and two parameters. The possible operators are:
6. See Maths for more info.
Expressions which are not mathematically valid e.g. I Am The Walrus > 5 give a warning and evaluate to false when used with a mathematical operator.
Goal: perform a set of actions for each of apple, pear and banana.
|Loop once for each of apple, pear and banana|
|2.|| Action One
||Example: Flash %item|
|3.|| Action Two
||Return to action 1 if we havn't done all the items yet|
Result: Action One and Action Two are performed three times. The first time, the variable %item is set to apple, the second time pear and the last time banana.
You can insert a
Goto action in the loop with either Top of Loop (meaning continue, skip to the next item straight away) or End of Loop (meaning break, stop without doing any more items) specified.
In adition to simple text, the
For action accepts any comma-separated combination of these Items:
A common case is to use %arr(), which performs a loop for each element in the array %arr.
Warning: the Values parameter in the loop is reevaluated with each iteration of the loop, meaning that modifying array variables which appear there from within the loop can have unexpected effects. To workaround that, it can be best to use the following sequence:
Variables Set, %values, %arrayWhichWillChange() Variable Split, %values For, %value, %values() ...
Goal: perform a set of actions for each of a set of elements in turn.Use the Foreach Loop as described above, with the Items parameter being a range specification e.g. 4:0, 100, 0:8:2 (= 4,3,2,1,0,100,0,2,4,6,8).
Goal: perform a Task X until some condition is met (at least once)
If %qtime < 20
|Return to action 1 if runtime < 20|
Result: Action One and Action Two are performed until %QTIME contains the value 20 or more i.e. until the task has been running for 20 seconds.
Note: %QTIME is a builtin local variable available in all tasks.
Goal: perform a Task X while some condition is met.
If %fruit Not Matches Apple
|Stop task if it's not crunchy, otherwise go to next action|
|Go back and see if we're still crunchy|
Result: Action One and Action Two are performed while %fruit contains the value Apple.
Goal: perform a Task X a set number of times.
|Initialize the counter|
|Add one to %count|
If %count < 10
|Return to action 2 if count < 10|
Result: after initialization of %count to 0, the task loops around the actions
from 2-5 until
%count reaches 10, at which point the condition on the
and the end of the task is reached.
Note that we used a
Goto to a labelled action this time. In
all but the very simplest tasks it's better to use a label rather than a number. It's easier to work out what's happening and if you insert or delete actions before the loop starts, the
Goto will still jump to the right place.
An alternative way to do this loop is to use a For action specified as 0:10.
Goal: perform certain Tasks if conditions are met, otherwise perform a different task.
%fruit ~ Apple
|~ is short for 'matches'|
|3.|| Action Two
%fruit ~ Pear
|7.|| Action Four
Result: actions One and Two are executed if %fruit matches Apple, Action Three is executed if %fruit matches Pear, otherwise Action Four is executed.
Else Ifs in a condition as you like
Perform Taskaction. To use it as a subroutine, you just need to ensure that the priority of the calling task is less than the priority of the called task (more info: scheduling).
The parent can optionally pass values to the child and receive a result back:
|1.|| Perform Task
Result Value Variable, %result
|pass 5 to the child, expect a result in %result|
|2.|| Variable Flash
|what did we get back ?|
|1.|| Variable Set
%newval, %par1 + 1, Do Maths
|add one to the value that was passed|
|set %result in the parent to the value of %newval in the child|
Result: the parent flashes 6
Returnstatements in most computer languages, Tasker's does not necessarily stop the child task, so if the child and parent have the same priority they can both run together and the child return several results over time.