20) Taking Action Over and Over Again
Apply Repeat actions in Shortcuts on iPhone or iPad
The Repeat action and the Echo with Each action allow you to run a grouping of actions in a shortcut multiple times in a row.
Using the Repeat activity
When you add a Repeat activeness to your shortcut, the activeness includes two markers: Repeat and Terminate Echo. Place the actions that you want to echo between the Echo and End Echo markers, and so specify the number of times you want the action to repeat. When the shortcut runs, the actions placed between the markers loop the number of times that you specify.
For example, a echo loop that contains a Vibrate Device action set to Echo 3 Times vibrates your iOS device three times when the shortcut is run.
You can place unlimited actions inside of a repeat loop. The actions run in gild (from top to bottom), and when the final activeness is reached, the shortcut loops back to the first action, and then runs again (the specified number of times).
Tip: You lot can place Repeat deportment within each other in your shortcut: In the shortcut editor, drag a 2d Repeat activity so that information technology overlaps the lower portion of the first Repeat action. The second Echo activity is nested (indented) under the commencement Echo action.
About information menstruum in a Repeat activity
For each iteration of a echo loop, the last action's output is gathered into a list, and that listing becomes the output of the Echo action as a whole.
For case, a Repeat activeness that runs four times and contains a Get Latest Photos action outputs the most recent photo saved to Photos in each iteration of the loop. Later all 4 iterations run, the outputs are gathered together, and a list of four identical photos is created. The four photos become the output of the Echo action equally a whole, and are so passed to the next activeness after the repeat loop.
To larn more about the menses of inputs and outputs, see Intro to how shortcuts piece of work on iPhone and iPad.
Tip: Touch and hold the Repeat variable to set up the number of repetitions to a variable. For case, if you add the Ask Each Time variable to the Echo variable in the Repeat action, you lot'll be asked to choose how many times the loop should repeat when the shortcut is run.
Using the Repeat with Each activity
The Repeat with Each action takes a listing of items as its input and so runs the same group of actions i time for each detail in the list. This is useful if you're working with multiple files or with multiple pieces of content. This type of loop repeats until every item that was passed into the Repeat with Each action iterates.
For case, if yous have a Get Upcoming Events action ready to recall the next four upcoming Calendar events and you identify a Repeat with Each action after the activity, the echo loop runs iv times and each iteration receives one of the Calendar events as input.
When you lot add a Echo with Each activity to your shortcut, the action includes 2 markers: Repeat with Each and Finish Repeat.
At the end of the repeat loop, the output passed to the End Repeat mark during each iteration is gathered together and passed as the output of the Repeat with Each activeness as a whole.
The Echo Particular variable
The Repeat with Each action offers a special variable for tracking the current detail: Echo Particular. The Repeat Item variable updates with each iteration of the loop, containing the particular passed equally input for that iteration.
For instance, if yous pass x Calendar items into a Repeat with Each action, the Repeat Item variable represents one of the Agenda events in each iteration equally the shortcut loops through each Calendar item.
Note: If you've placed a Echo with Each action inside another Echo with Each activity, the variable proper noun changes to Repeat Item 1 to stand for the inner repeat item, to Repeat Item 2 for the deeper loop, and so on.
The Echo Index variable
All echo loops offering a special variable called Repeat Index, which is used to continue rail of the current iteration of the loop. The Repeat Index variable contains the number of times a loop has been repeated so far, starting at i for the commencement iteration of the loop and incrementing past one each time. The second time a loop runs, the Repeat Index is 2. The tertiary time a loop runs, the Echo Index is 3, and so on.
Note: If you've placed a Repeat action within another Repeat action (created nested repeat loops), the inner Repeat action'due south variable proper noun changes to Repeat Index two. An additional nested Repeat action would offer a Echo Index iii variable, and so on.
For more information, come across Use variables in Shortcuts on iPhone or iPad.
Create infinite loops
Although Shortcuts doesn't offering an activity to repeatedly run a group of actions forever, you can emulate this behavior by using the Run Shortcut action. The Run Shortcut action allows yous to run i shortcut inside of another. Configure the Run Shortcut activity to run the same shortcut that it's independent within, and the shortcut runs from commencement to finish repeatedly until you lot stop the shortcut.
Test the output
When y'all're learning to work with Echo and Repeat with Each, it's helpful to examination the results that are produced after the End Echo marker to ensure that the content is what y'all intended. Place a Quick Expect activeness subsequently the Cease Echo marker to preview the items that are output past the repeat loop.
Yous can also place a Show Alert activeness after the Terminate Echo marker and insert a Repeat Results Magic Variable in the message box to display text that has been output past the loop. If you lot're testing a loop that's in the eye of a long shortcut, it'due south helpful to utilise a Show Alarm action to preview results, considering you can include a Cancel button in the alert to end the shortcut at that point in the loop.
Source: https://support.apple.com/guide/shortcuts/use-repeat-actions-apdc11deb2c1/ios
0 Response to "20) Taking Action Over and Over Again"
Post a Comment