This activity allows you to apply various business logic to algorithms and perform certain actions depending on the conditions you set.
There are two modes of working with the "Condition" parameter in the "If...then" activity:
Basic - this mode involves using the visual editor to set simple conditions.
When you click on the "Edit condition" button you will see such a window:
At the top of the window there is a working area consisting of three parts - data component - operator - data component.
At the bottom of the window are available elements - data and operators.
Data can be a boolean type -
false, explicit data - text or number, and a variable. Operators define a condition for comparing components.
Suppose that the condition should be: "If the variable
price is greater than
1000, then". Let's set this condition using the visual constructor. To do this:
- Drag and drop the "Variable" block into the left-hand data component. After dragging it, you will be able to set the name of the variable. In our case it will be
price. If you want to change the variable name, click on the pencil icon.
- Next, drag and drop the "Number" block into the right-hand data component. You can set or change the value of the component similar to the first action. Set the number to
- Now drag the "Greater" block to complete the condition.
This way, the condition will look like this:
Click Save. The "If...then" block will appear ready to work on the canvas.
In the toolbar on the right you will also see the specified condition.
Similar to the example above, we set the same condition - whether the value of the
price variable is greater than
This is what a complete algorithm with a condition might look like. Here we have some variable with a value assigned to it. We apply the "If...then" check to it (if the price is greater than 1000) and output the result to the console.
The algorithm from the example above and the result - the checked condition
price > 10 //checks if a number is greater than 10
(milk_price < 10) && (bread_price > 15) //checks if both conditions are met
ocr_data.includes('Total') // checks if data returned by an ocr engine has the word "Total"
number_in_system === user_input // checks if some number in system is of the same data type as the user input and if they are equal in values
number_in_system == user_input // checks if the values are the same if one of the variable is automatically converted to the type of the other variable