Search
Tuesday
Aug302016

Workflow Example: Loop & Pause

This workflow is just an example of how you can use loops and delays and demonstrates a way you could keep checking for something over a period of time and then escape from the checking loop once something has occurred. The example here is based on the user choosing to end the check, but you would more likely set this to be some sort off automated check such as checking that some content has appeared on a remote URL or perhaps a change in state of something on device.

The workflow begins by initialising a couple of variables to be used in the checking. It doesn’t actually matter what the content of these is as long as they are set to be the same. Because of this we can actually use this to hold a particular piece of text that will be of use later in the workflow and make it a little more efficient than setting this text up separately. The workflow sets up a set of actions that will be repeated (up to) five times.

Those actions begin by checking a variable to see if the user has selected to exit the repeated actions. If the check is still matching as “Loop not manually exited” the workflow will pause for two seconds and then display a question to the user asking if they would like to continue in the loop or to stop and exit the loop.

If they choose continue the workflow displays an alert to indicate an action could be run. This is where you might check for a change in a web page or some other change externally or in a device property/state.

If they choose stop checking then the Check variable is set to some informational text stating on which loop the user chose to exit. If this option is chosen, when the loop begins again and the check variable is checked, the app will note that the content has changed from it’s original value. It will repeat the remaining loop iterations, but it will not run any actions other than the check for the change. By having all the actions in the repeat loop inside the If action we can effectively jump out of the loop by doing nothing for all the remaining repeats.

At the end of the workflow an alert is displayed to the user. This contains the content of the check variable. If the user did not choose to stop checking this will contain the original content of the variable. If they did choose to stop it will contain the text indicating that they chose to stop and on which time through the loop they chose to stop.