What Are Control Flow Statements?
Control flows are the backbone of automation. Identifying what to do with a set of data – and how – is a key component of high-value automation, but it can also be confusing to wrap your head around at first. What is a conditional? And what does it have to do with a loop? How do you deal with a set of information versus a single data point?
Understanding the exact components that you have to work with is important for identifying exactly what you can do with the data at hand. There are a number of ways in which data can be manipulated, routed, and interpreted within a workflow, and control flow statements are a solution to handling it. Modern automation solutions like Torq’s no-code platform are able to handle these steps visually with a drag-and-drop platform.
Types of Control Flow Statements
Control flow statements, like we see in Torq workflows can be isolated to just a handful of components: if, loop, break/exit, and wait. Each of these components, also called “control steps,” can be used to control the flow of information within a workflow, allowing you to perform actions only as needed.
A “conditional” is, in essence, a comparison between two values that determines whether or not a workflow will run. While strict comparisons can be used (like checking if a value is equal to the number 10, for example), more advanced conditionals can be used. For example, you can check if a value contains another value, use standard greater/less than comparisons, or even perform more complex comparisons using regular expressions. It’s important to note that conditionals are used to gate workflow runs; if you need to compare values within the context of the workflow itself, see the “if control” below.
An “if control” is the term used for “if-then-else” statements. In other words, an if control is what happens when you check if a given condition evaluates to true (for example, when comparing two variables, the time of day, or the number of iterations in a loop). If it does, then some pre-defined behavior happens (for example, a notification gets sent, more data gets downloaded, or a new workflow gets triggered). In automation, if controls are king, as they determine what happens, when, and why.
When dealing with a set of data (such as a list of names or IP addresses), you often have to “iterate” or “loop” over the data and run operations on each individual entry. This could be as simple as posting a message to Slack for every entry, or as elaborate as integrating with a dozen third-party solutions to determine the threat model for a given IP address.
A “break” and an “exit” control do exactly what they say: stop a loop from executing. Within a program like Torq, the only difference between them is that an exit can be bound by a conditional, while a break happens immediately.
Sometimes data needs a minute to breathe before you can act on it. This is where a “pause” (or “wait”) comes into play. Unlike conditionals, loops, and breaks, pauses do exactly one thing: nothing. A pause is an opportunity to let any third-party services catch up before continuing the automation, such as when you need to be sure that an email has arrived before moving on to the next operation.
Nesting Control Flows
A nested control flow is a great solution for building and maintaining DRY workflows within Torq. What is DRY, you ask? It is a coding principle that stands for “don’t repeat yourself.” Rather than duplicating a set of actions across multiple workflows (or within a single workflow), you can isolate that set of actions as a nested workflow and re-use that component as well. That way, if you need to make a change to the nested workflow, you only have to do it in one place instead of several.
Using control flows to move data around is interesting and generally helpful, but what automation is really intended to solve is performing actions automatically. It doesn’t matter how many IP addresses you can parse if you don’t do anything with the information, which is where “action steps” come into play.
This is the point at which the external integrations get used. Once you’ve identified the information you care about, whether that means pulling down additional data from a third-party API or posting information to a webhook owned by the engineering team, the action steps bring everything together into a valuable internal tool.
Connecting the Dots
In the abstract, automation can feel overwhelming. There is a lot of data to deal with, and a lot that you need to accomplish with it using minimal human intervention. But, once you wrap your head around the power of loops and conditionals, you can start to see how you can accomplish truly powerful things.A great exercise when getting started with workflow automation is to think about what data is coming in and what data is going out. Understanding what you want to do with that data will help define how your workflows will come together. Whether you are sending an email for every entry in a list received from a Slack message or simply downloading additional information for an IP address that gets logged, you can easily accomplish your task using this simple set of building blocks.