A beginner’s guide to ‘IF’ statements
IF you want to understand the basics of if statements THEN read this article, ELSE explore our blog for more content.
Automation software (like ThinkAutomation) needs to be told what to do. One way to do this is with if statements. You can use them to automate almost anything — from simple, single tasks, to complex processes and workflows.
But what are they, how do they work, and how do you write them? All will be made clear in this beginner’s guide to if statements.
What are if statements?
If statements are logical blocks used within programming. They’re conditional statements that tell a computer what to do with certain information. In other words, they let a program make ‘decisions’ while it’s running.
They’re comprised of a minimum of two parts, ‘if’ and ‘then’. However, there are also options such as ‘else’ and ‘else if’ for more complex if statements.
A good way to think of the if statement is as a true or false question. They ask the program if something is true, and tell it what to do next based on the answer.
So, if statements essentially mean: ‘If something is true, then do something, otherwise do something else.’
How do you write your ‘if’ blocks?
If statements are formulaic to write. No matter what the scenario, they always follow a similar set pattern. ‘If’ outlines a condition, and ‘then’, specifies what should be done if the condition is true.
‘If’ can ask for a variety of different properties, such as ‘contains’, ‘is greater than/equal to/less than’, ‘starts with’, ‘is not blank’ etcetera. These properties are how you fine-tune your rules and let the computer know what to look for.
How do you execute your actions?
You use logical operations to conditionally execute your desired actions. This is the ‘then’ part of the if statement that specifies what should be done when the ‘if’ property is true.
Here, you can use properties such as ‘pass value to trigger’, ‘next loop’, ‘comment’ and so on. Meanwhile, ‘else’ outlines what the computer should do when the ‘if’ property is false.
Multiple actions, minimal if statements
You can use a single conditional ‘if’ to trigger multiple actions. This is done simply by listing all the actions that need to be completed in the order you want them completed in. For example:
‘IF an incoming email contains %invoice%, THEN forward to [%email%], add to %database%’
This would mean that any incoming emails that have the word ‘invoice’ in are both forwarded to the specified address and added to the specified database.
However, this is just a simple scenario, and if statements can lead to a detailed sequence of actions before closing the loop with a logical ‘end’ operation.
How do if statements work together?
There are a few ways that if statements can work together.
It’s possible to nest if statements into other if statements. This means that the ‘then’ part of your if statement triggers another ‘if’.
‘IF [value] is greater than 70, THEN IF [value] is less than 80, THEN IF [run action]’
Then, there’s ‘else if’. ‘Else if’ tells the computer that when the ‘if’ condition is false, it needs to trigger another if statement to determine what to do next.
‘IF an incoming email contains ‘invoice’, THEN forward to [email address], ELSEIF the incoming email does not contain an attachment, THEN add to junk mail.’
If statements also interact separately from each other. For example, one of your if statements sends some incoming data from your email to the correct database. Then, another of your if statements checks your database for new entries and runs actions on the results.
If statements and ThinkAutomation
If statements are the foundation of a rule-based system. With them, you can automate simple actions or even detailed workflows.
But even if you understand how they work, writing if statements with code is still a daunting task. That’s why with ThinkAutomation, you can set up your if statements with no coding necessary. Instead, simply drag and drop your desired triggers and actions to make your own automated processes.
Why not give it a try with a 30-day free trial?