Replicating If Statements, For Loops and Do While Loops in Microsoft Flow

Adam Murchison, 29 October 2019

People who know a little bit about programming may need a good starting point for understanding how Flow works and how they can replicate their programming knowledge in Flow.

When first outlining a solution to a problem I break the problem down into pseudocode, a logical set of actions that I then use as a skeleton for a program. While coming up with a solution to a problem I had using Flow, I decided to make a list of components that are used in place of if statements, while loops etc. I’ll show you all the controls I found and regularly use.

Most of the controls that are used for the replication of if, for and while statements are found under the connector ‘Control’.

If Statement

The if statement in Flow can be used as shown below. You can add in multiple different conditions.

In this example I’m saying that if the temperature is greater than 20 and less than 30 OR the location is Christchurch. If ((Temperature > 20 AND Temperature <= 30) OR Location = Christchurch)

This is just one example of how you could use the Condition control like an if statement.

For Loop

In most programming languages, a for loop is used to iterate a list or collection of items.

In Flow you can iterate through a list or collection and perform an action on each item. In this example I’m using the Dynamics 365 connector, I retrieve all Accounts and update them with the location from the MSN Weather connector.

The ‘Value’ part of the ‘Apply to each’ is the list from the ‘Get Accounts’ method which is the collection of records. The ‘Current Item’ is a dynamic field created in a ‘Apply to each’ which is the unique identifier of each record in the collection. This will change depending on the collection, in this example it’s the ‘accountid’ field which is the unique identifier (Guid) of the record.

Do While Loop

A Do While loop is used to create a loop that executes until a condition is met. This can be replicated in Flow by using the control ‘Do Until’ which can be found under the ‘Controls’ connector.

In the following example, you can see it will execute the method ‘Training Done’ until the ‘Status code’ is equal to 200, effectively looping through while Status code is not equal to 200.

The main difference between Do Until and Do While is Do Until will execute an action after a condition is checked and Do While will execute an action and then check that the condition is true, prior to executing the action in the next iteration.

In summary there are many different components that are used to replicate a software program or process. I hope these steps help you transition from writing code to using Flow to facilitate how you solve software problems!