How to use Loops in Microsoft Power Automate Desktop

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in power automate desktop we have different kinds of Loops let me show you the most important ones first of all we have a 4-H a for each each rates through say a list or data table that's the most common ones so let's create a list that we can iterate through with the forage I'll find the set variable and let's give our list a name I'll just call this any Mouse and then let's create a list to create a list you'll have two percentage signs in the start and in the end add brackets done in the end and then we will have the list items inside these hard brackets in single quotation mark put in your first element that will be dark and then I will say cat and let's have a third like this so three elements in our list that we can iterate through and I can click save Here Comes our for each so I'll drag in a for each what value do I want to iterate I want to iterate to the animals up here so I'll say animals I'll store them into a current item variable that means that now we have three so and we are looping through them one by one so that means whenever we are in the first occurrence we can refer to that item as q and item here it will be dark then the next iteration takes place the Q a item will now be cat bird and so forth if we have more elements so let's storm into an animal Parable instead and here you can see so the list is called animals and then each item when we Loop true with a for each that is called animal this is just a reference name you can call it whatever you want but best practice is to use a name with some meaning to the data in that way it will get later it'll get easier later on if you want to update your flow or if your colleague wants to so then I can click save now let's just print out the names so very very simple but I'll find a display message as we often use when we want to display messages so here I can just refer to this animal here so I click this little X say animal make sure you pick the animal and not the animals but then I can click save I click run dark cat bird that's how easy it is to use a 4-H now we want to use a loop so and let me click this for each up here hold shift in Click the end right click disable action it's just because I find it annoying when we move to the next example to show these pop-ups so but you can find have him if you want so let's have a loop and a loop is doing something x times let me show you so let's drag in a loop and here you can see I actually accidentally dragged it in before the end I'll just have it here so I want to start from one I want to end at 5 with increments of one so this Loops run five times one two three four five very easy if you do is a variable called Loop index and that is an index of what Loop we add so first it will be one two three four five very straightforward then I can click save again let's try to display a message here and here I'll just write out the loop index so click this little X here take the loop index and we could say this is run number like this space and then we'll have the loop index so now when I run the loop it says this is run number one two three four five that is a straightforward Loop often we are using its cousin called Loop condition so let me again Mark all these things and disable this so now I want to um do the loop condition in a loop condition evaluates on something and whenever this is true the loop will continue we'll often use it when we want to check for elements at the web page say that we want to post the flow um and then look for an element if that element is not present then we want to pause it further and maybe pause it for like uh 10 or 20 Loop iterations of maybe 10 delayed seconds so we can use it to check for something and then make it last a while let me show you so here I'll have a loop condition and I'll drag it in actually I dragged it in before the end it will go in after but let me show you we can move it afterward so the first operand now we need to to have an operand and since we don't really have it here we can say we can say if 2 equals to save and let me just move this end up here so this is essentially an infinite Loop this is always true so if I run the robot here you'll see that I have now created an infinite Loop it will run forever because this condition is always true so and this is not really best practice as you can see this run this robot will run forever but imagine that it takes some hard system accents right now it's just running it will not take any system resources but you can actually create a very bad robot that will run favor so always do your conditions so they can change or make a handbrake I'll show you both of the things first it's just instead of here we will have something to evaluate on so I'll find a display um input dialog here I will take I'll ask the user for some input and then I'll save it as a variable I will drag it in in the loop or condition here so here I want to say the title that could be capital and here I'll make A's little quiz what's the capital of Denmark and then the user will give me an input so that will be stored here in user input let us call that capital for easier reference then I can click save now I only want this Loop to run until the user has the that the capital value is code making because that's the correct answer so if I go up here in Loop condition and then say the first operand let us just say Capital if that is equal to Copenhagen like this then it will run so right now we just need to change the operator to say not equal to so now it will run as long as this Capital variable is not coping let me show you so and let me just drag it in over here so what's the capital of Denmark I'll say London it will run much more let me just do one more fail so room come in here and let's just pick coping it's now finished so it finished because um this one was not true anymore so the capital is not Copenhagen it's not equal to Copenhagen then this will run but now it became coping so this became true and it stopped so a loop will evaluate on something when it goes in run the actions inside it evaluate again and continue but what is what if if our user was very didn't know the capital of Denmark then we created an infinite Loop that could essentially run on limited times I know that the user will probably get bored after five attempts and then just leave the computer shut the flow down but imagine that this was some unattended robot that checks for something then we wanted to to have some sort of a break in the loop condition and this is very important and for this I need some sort of account that says only run this Loop x times so I'll find a set variable here and then I'll drag it in here so here this one I will call this Loop index and it will start at one I only want to run it 10 times so I also need to each time a loop has run I also need to add one to this so pick a set variable in the end of the loop and this is actually something that you'll use a lot so please pay close attention so the value like this x here I'll add one to the loop index whenever we reach the end of the loop so that will be plus one here I don't want to make it 10 because then I need to make 10 guesses so let's just make it 5 to make it easier for ourselves but you can of course change it up here in the loop condition so right now we can only do um we can only do one condition but we can actually make more conditions inside here we just need to make it a little bit different so what we can do up here is that we can say if the capital is not equal to and then it's coping like this and now you just need to have it in a single quotation marks because the capital is available Copenhagen is not that's just text so that's why and then we also need so we know we need to have an end and then we can say if this is Loop index we only want if the loop index is is um is less than or equal to 5 then we want it to run when the loop into six six that means that the loop had ran five times we don't want to run it anymore so that's it's just below six and we can write it like this so if the loop index is less than six then so we only want this to run whenever the capital is not equal to government and loop index is six so this is an expression and now we will change it to equal to true so we will only run run this Loop condition as long as this expression appears true that is if the capital is not correct guessed and the loop index is below 6. little C so now we can run it and um I'll just show you here and I need to drag it in here so now the loop index is one you can see it over here let us just press a now the loop index is two I'll just press B not correct answers so C and that's why I didn't want to make it a d and now to be the last one because the loop index is five this is still true but next time it would be six this will not be true so we will stop our loop I don't know where when that so that will be e there you go we have now make that backdoor this is a very important concept so if you didn't know what if you didn't understand what's what went on here with the set two set variables and the condition please rewind the video and do it thank you and your next lesson is up here that will take you to another important power ultimate desktop concept
Info
Channel: Anders Jensen
Views: 10,418
Rating: undefined out of 5
Keywords: anders jensen, power automate desktop, how to use loops in power automate desktop, loops in power automate desktop, for each loop in power automate desktop, loop condition in power automate desktop, power automate desktop tutorial, loop in power automate desktop, power automate desktop loop, power automate desktop loops, power automate desktop for each
Id: QOM0GG7k_Pw
Channel Id: undefined
Length: 11min 15sec (675 seconds)
Published: Mon Oct 10 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.