Chapter - 6 Operations

50 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€95.86
List Price:  €134.21
You save:  €38.35
£79.54
List Price:  £111.35
You save:  £31.81
CA$143.56
List Price:  CA$200.99
You save:  CA$57.43
A$159.95
List Price:  A$223.94
You save:  A$63.98
S$135.54
List Price:  S$189.77
You save:  S$54.22
HK$777.41
List Price:  HK$1,088.41
You save:  HK$310.99
CHF 89.37
List Price:  CHF 125.13
You save:  CHF 35.75
NOK kr1,131.89
List Price:  NOK kr1,584.70
You save:  NOK kr452.80
DKK kr715.08
List Price:  DKK kr1,001.15
You save:  DKK kr286.06
NZ$176.78
List Price:  NZ$247.50
You save:  NZ$70.72
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,900.85
List Price:  ৳16,661.67
You save:  ৳4,760.81
₹8,494.03
List Price:  ₹11,891.98
You save:  ₹3,397.95
RM450.75
List Price:  RM631.07
You save:  RM180.32
₦154,505.46
List Price:  ₦216,313.83
You save:  ₦61,808.36
₨27,720.51
List Price:  ₨38,809.83
You save:  ₨11,089.31
฿3,419.79
List Price:  ฿4,787.84
You save:  ฿1,368.05
₺3,506.82
List Price:  ₺4,909.70
You save:  ₺1,402.87
B$608.53
List Price:  B$851.97
You save:  B$243.44
R1,831.63
List Price:  R2,564.36
You save:  R732.72
Лв187.37
List Price:  Лв262.33
You save:  Лв74.95
₩144,627.53
List Price:  ₩202,484.33
You save:  ₩57,856.80
₪363.83
List Price:  ₪509.39
You save:  ₪145.55
₱5,882.91
List Price:  ₱8,236.31
You save:  ₱2,353.40
¥15,642.93
List Price:  ¥21,900.73
You save:  ¥6,257.80
MX$2,007.92
List Price:  MX$2,811.18
You save:  MX$803.25
QR363.05
List Price:  QR508.28
You save:  QR145.23
P1,376.48
List Price:  P1,927.13
You save:  P550.64
KSh12,857.29
List Price:  KSh18,000.72
You save:  KSh5,143.43
E£5,087.81
List Price:  E£7,123.14
You save:  E£2,035.32
ብር12,414.52
List Price:  ብር17,380.83
You save:  ብር4,966.30
Kz91,790.82
List Price:  Kz128,510.82
You save:  Kz36,720
CLP$98,780.55
List Price:  CLP$138,296.72
You save:  CLP$39,516.17
CN¥729.56
List Price:  CN¥1,021.42
You save:  CN¥291.85
RD$6,064.47
List Price:  RD$8,490.50
You save:  RD$2,426.03
DA13,486.35
List Price:  DA18,881.43
You save:  DA5,395.08
FJ$231.62
List Price:  FJ$324.28
You save:  FJ$92.66
Q767.35
List Price:  Q1,074.32
You save:  Q306.97
GY$20,835.60
List Price:  GY$29,170.68
You save:  GY$8,335.07
ISK kr13,848.23
List Price:  ISK kr19,388.08
You save:  ISK kr5,539.84
DH1,002.31
List Price:  DH1,403.28
You save:  DH400.96
L1,836.70
List Price:  L2,571.46
You save:  L734.75
ден5,897.23
List Price:  ден8,256.37
You save:  ден2,359.13
MOP$797.27
List Price:  MOP$1,116.21
You save:  MOP$318.94
N$1,833.49
List Price:  N$2,566.96
You save:  N$733.47
C$3,664.75
List Price:  C$5,130.79
You save:  C$1,466.04
रु13,546.73
List Price:  रु18,965.97
You save:  रु5,419.23
S/370.84
List Price:  S/519.19
You save:  S/148.35
K403.85
List Price:  K565.40
You save:  K161.55
SAR375.59
List Price:  SAR525.84
You save:  SAR150.25
ZK2,756.13
List Price:  ZK3,858.69
You save:  ZK1,102.56
L477.10
List Price:  L667.96
You save:  L190.86
Kč2,408.98
List Price:  Kč3,372.68
You save:  Kč963.69
Ft39,690.03
List Price:  Ft55,567.63
You save:  Ft15,877.60
SEK kr1,103.14
List Price:  SEK kr1,544.45
You save:  SEK kr441.30
ARS$101,779.64
List Price:  ARS$142,495.57
You save:  ARS$40,715.92
Bs688.19
List Price:  Bs963.50
You save:  Bs275.30
COP$435,927.07
List Price:  COP$610,315.34
You save:  COP$174,388.27
₡50,246.58
List Price:  ₡70,347.23
You save:  ₡20,100.64
L2,528.04
List Price:  L3,539.36
You save:  L1,011.31
₲776,552.46
List Price:  ₲1,087,204.52
You save:  ₲310,652.05
$U4,441.97
List Price:  $U6,218.94
You save:  $U1,776.96
zł408.81
List Price:  zł572.35
You save:  zł163.54
Already have an account? Log In

Transcript

Chapter Five data operations. Up till now, we have discussed what data variables are, what are the major different data types that are associated within UiPath. What is a variable scope, and how we can play around with the variables to achieve some output, right. In this section, we'll be talking about the different computations or the operations that we can perform on the variables. Right. In this chapter, we'll be going through an overview of what data operations are.

We'll talk about basic arithmetic operators, relational operators and logical operators. We'll talk about controlling the flow of an execution of the execution of a program. And we'll also talk about loops. Alright, overview UiPath provides a rich environment for operations. operations are simple computations, which when performed modifies the raw data which is provided as input into meaningful dat data, which is called as output. This concept is often regarded as data processing.

For example, 1354267 are simply random numbers raw data, but when arranged in ascending order, which is a data operation, they form the first seven positive integers of number line, which is a meaningful information. The operations within UiPath can broadly be categorized into arithmetic, relational, and logical operations. basic arithmetic operations, mathematical operations like addition, subtraction, multiplication, and division all work exactly the way you would expect for numeric data types. These operations don't work for other data types like Boolean object, date, time, etc. However, addition operation can be used with string variables, where it concatenates the two strings provided to it as an input. Additionally, we also use a modulus operator, which gives the remainder of division operation.

It is denoted by the marquee word as shown here. A quick example would be say 25 mod four will give the result as one. Right. So let's create a sample program to see how arithmetic operations work. So we have a workflow in here. And what we're going to do is we are going to have three variables called number one number two, and the sum which is going to store the sum of these two variables.

Right. So we've already discussed what default method is, but in this program, we will be taking the input of what What number these these variables should hold from the user himself, right during the runtime. So for this, we have an activity called input dialog, we enter the input data because we'll be entering the first variable data value in it will also add another input dialog to enter the value for the second variable. And then we'll be doing the arithmetic operation operation of addition to store the value of that operation in the sum variable. Alright, so input dialog, we should always name our activities in the most effective way so that you know it becomes comprehensible to any other person. So input first, variable value, something like that.

And what's the title of the window that will be displayed to the user where he will be putting in the information Enter variable one, value number one, something like this is the label which is going to be presented next to the text field where again the data will be entered. And for the second activity, we'll put in the second variable. See these are because the all these are simple text messages, simple static text that we are going to present in front of the user. So we always have to enclose them in double quotes, as we've already mentioned in the data variables chapter. And now we want to perform the computation the operation so we'll use an A Operation assign activity. And in the sum variable which we already created, we are going to say just store number one plus number two.

Right. And currently, if you have seen, we have just given the names of the text fields and everything in these two input dialog activities. But we haven't denoted anywhere yet that you know the value that will be entered by the user should be stored in this number variable, right. So what you should do is in the output of this activity needs to be stored in this variable number one, and similarly for the second operation for the second activity, the output variable would be num two. All right, and now we have computed the sum and we want to print the output of the Sun This play edition. This is gonna be some remember doc to string because we need to implicitly convert the string.

If it was a string variable, everything would have been okay. But in here we need to write, and this is a pretty decent program, you can see, right we entered the first variable, we enter the second variable, we assigned the value to the sum variable, which is going to hold the value of number one plus number two, and we're going to display the sum variable. We always should save our program before going further. And just by running it, you can see that let's that the first window has been created. And let's say we want to win first number and the second number is going to be let's say five. So the sum is seven.

Being displayed and here is our program works perfectly. So you can try other operations as well like subtraction, multiplication, division and modulus operation as well. And they come pretty handy when we are, you know, working on actual programs or when we are getting some data from a file from any external target application. And you know, we might need to do some computations to to store the values in the workflow itself and use them further. A few points Remember, the input dialog activity requires the input from the user, a window will be displayed as it was shown. And it's going to have the label text and the title of the activity as well.

And the enter data will be stored in the variable which we have provided in the activity itself as the output variable. Right. And data always needs to be in the text format. Also, we have already discussed this before, but if you didn't want to, let's say Stop the execution of display by displaying this value of the sum variable, what you could have done is you could have used the right line activity and what would it have done it would have stored the value of some variable I mean not stored but displayed the value of the variable in the output panel right okay. Next, next is going to be the string manipulations. So, strings are considered to be the simplest form of arrays.

A string is an array of characters forming a text. And there are various string manipulation functions supported within UiPath some of these are shown in here. So contains is going to check whether some text some substring is a part of, of a full fledged string or not. If so, if it is a part then it's gonna result in a boolean value of true or false it's gonna say false and we can perform our This is like a quick decision way and decision flow and we can continue with our, with the rest of the execution accordingly. Then we have a replace method which is going to replace some text with the new text that we're going to provide in the activity itself. We have split function to split a string based on some delimiter.

Like sometimes you don't want spaces in a text. So you can simply take them out or something like that. Then trim is used to trim certain part of the string like you know, if you want to trim from the start, let's say first 10 characters, you can do that trim with the end first 20 characters you can do that something in between, you have to provide the starting point and the ending point within the trim statement and you should be able to do that. Then we have to lower to upper functions which are which is going to convert the whole string into uppercase or lowercase. And this ends with and starts with with checks if a string starts or ends with some particular characters that are, again provided within the article. Or within the function parameters itself.

Okay, and these predefined functions are provided by dotnet framework and are accessed using the dot operator like we use.to string, right. So after to string, you can use these functions as well because there are multiple functions that can be added to one data variable itself. So, let's say there's a string, welcome to UI path, then you can say, dot split or dot contains or dot replace or anything. Right. And that's pretty much it for the string variables. We'll be using them when we will be extracting data from Target applications in our subsequent chapters.

But you can always play around with it some static text and see if you can if you're able to, you know, get the desired output or not. Next is relational operations. So relational operations define the relationship Ship one operand has to the other. In practical scenarios, these are mostly used in making decisions and the validity of the condition. Data mined the further execution of a workflow. They determine the quality and ordering.

And a few of these relational operations are shown in here. Like equal to is going to check whether the number is equal to or this or not. And we can continue again, if it is not equal, we're going to get some we're going to process Let's see some other operations. And if it is, then we may have a different set of operations that we want to perform. Right, if not equal to is like a beginner in less than sign put together. And then we have greater than and smaller than science well to check whether let's say we have two integers number one and number two, as we just showed, right?

So we can check if number one is greater than a number two and based on that computation, we can perform our further operations And we have a greater than or equal to as well and we have smaller than or equal to as well, which is going to check the equal to condition as well, in the greater than its if even if they're equal, it's going to be considered as a false situation. But if you want to consider the equal to as well, then we have to put that in the operations symbol. Okay, so we can use the same activity, I mean, the same example in here. We have number one and number two values in here, right? And what we can do is we can use the low decision let's probably do that right away. This is a condition that's going to check whether a number is greater than something or not.

And if it is, we can perform the competition in some way. If not So we'll be discussing this in this chapter itself again, but just a quick example right. So, this is for true. So something like this. We are printing the message that you know number one is greater. If not, then now let's use the right line All right, and This pretty much it we can we have checked the condition as well.

And let's run this. So number one is 43. And let's say number two is 12. Then number one is better screenshot correctly. So a few points to remember in conditional statements is that you know, a conditional statement is mandatory. When we'll be using flow decisions.

The validity of the condition decides the direction of further execution of that workflow right. Then, the message box activities same as right line except it prints the message in the message window instead of the output panel. And, you know, you should always try to give meaningful names to the activities within the workflow. This helps in better comprehension of your solution to the business problem at hand. All right, this brings us to the next operations called the logical operations. logical operations are the ones that act on Boolean operations and form a resultant boolean value, right?

There are only three logical operations, namely and or not. And what they do is for any Boolean expression, let's say a and b, effect of each of these logical operations is shown in here. So if there is a, a, which is the Boolean operator, which holds the value true, and B is also true, then the A and B which means both A and B should satisfy and that's where it gets true. If A or B, that means if any of A or B is true, the condition is true. And we'll be using them all of these operations when we will be working with the conditional flows and even in the loops. Okay, For the execution of a workflow needs to be thoroughly regulated and managed to make sure the bot performs precisely as per the business needs.

Control flow refers to the concept of causing the flow of program to advance and or to branch to the next state based on the validity of the current state. It defines the rules and validations performed by the workflow. This goal is accomplished by using FL and loop activities among others. control flow constitutes the most crucial part of any programming language. if else decision, if activity is like a conditional branching activity, that directs the flow of execution based on the condition that has been provided within it, as you can see, the program can be routed into different paths, right. If the condition is going to be true, then the true state will be executed, else it will directly go to the else statements and when the conditions are not valid, the statements would be performed.

Let's take a quick example to showcase how an if statement works. So we have two variables input and output. And it is going to be pretty much same as the same condition we'll be taking which we also used in the flow decision and we'll be discussing that but if save number one is greater than number two, then let's say you want to brand l In the right line activity will print the same stuff that says write exactly the same stuff that we did just now. And here, we see the conditional operator is going to be a greater than symbol but could have been anything else number one is greater than equal to, is strictly equal to or smaller than or some other operation could have been performed right. And there might have been a few other computations involved before even getting to this statement. So that again, depends on what the program is, and check or compare value.

Okay, now if you run the program, we get the statement that says enter the number one, which is going to be let's say 12. number two's this time we'll keep it higher. And boom program, nothing happened. Why? Because you see here this right line statement. So if you check the output panel, I, it says number one is smaller. All right.

And that's how we use the if statement to do some conditional operators say, if you want to check that number one is greater than number two. And you know, there's a logical operator and a number one is equal to 23, something like that, right? So you want to see and is 23. Else. Let's say we want to print invalid, something like that, I mean corrupting anything. So in that case, if number one is greater than number two, and number one is equal to 23, as well.

Both conditions search should satisfy to execute the conditions to execute the activities which are provided in the den sequence. Else. If any of those conditions are false, then it will directly execute the statements. Correct. So, that way if we run out, I mean, it makes sense that you know, how the program execution is gonna go. A, let's give it a shot.

And then number one, we're gonna put it as number 23. This time, and is it smaller or greater? greater, it's not gonna work, right? Because number one is not good is the number two. So again, the output is going to be invalid. terrorists.

All right. So it doesn't matter even if one condition is true or something. Both the conditions have to be true to make it working. Okay, let's go To the next conditional statement, it is called flow decision as already been touched upon flow decision is another conditional activity used within flowcharts. Usually within flowchart course, to make decision based on the accuracy of the condition it holds, it includes a true node and a false note, as we have already discussed, and both of these are connected to the further actions that are needed to be undertaken by the program. Right, it is shaped like a diamond.

And the actual activity looks exactly like what we showed before. You can check the flow decision by simply so becomes really easy, you know, because you have all you have to do is just simply search for the activity in the search panel here within the activities panel and this use the activity right there. Right, here's what we're putting the condition for. It's a very common concept that is used in any flowcharts right. So, usually In flowchart itself because of the connectivity, that's how we denote, and it becomes very, very easy for any external person to look into your program and actually get to understand what the logic behind it is. Right?

Because flow decision, okay, true false, yes. For if condition, you'll have to go into a and, you know, you have to see how it looks like and you have to put some, you know, I mean, you have to work a little easier effort is going to be a little extra in terms of in terms of understanding what the other person probably has implemented as the logic in their workflow. So, that's how we use a flow decision as well. And we've used a sample program before so we're not gonna get into that again. Let's get to the next activity. switch statement.

Okay. So that's, again, a very good statement. I mean, In terms of its usage, search activity is a multi way branching activity. It provides a simple way to carry out the execution of workflow to different paths based on the value of an expression. In simple words, it provides an optimal alternative to a large series of if else activities. The general form is already shown in here.

And what's going to happen is in the expression that we have provided, next to the switch statement, it's going to evaluate the expression and based on the case number, let's say the result of this expression comes out as one, then the first operation would be executed. If the value is case two, I mean, which is like numeric two, then operation two would be executed which could be sequence of activities and if none of the use cases that we have provided In this statement holds true, then it's going to go to the default, which is going to be like, after everything has been processed and checked upon, then it's going to go to the default and execute the default statements or the activities that we are provided. So we are going to take a quick example in this as well. And for this, what we are going to do is, we're going to consider that, you know, we have to display the value of an integer variable, and we have to check whether the value that that integer variable holds, does it live between the range of one to five?

If it does, good, we will print the value or we'll print a message displaying the value of that. That variable but if not, we're gonna print the message as invalid or not valid or something. Right. So what we're going to do is we have we don't need This variable so that's okay. We're not gonna use the second variable at all but I'm keeping it as is. And here's the switch statement.

And expression is gonna be let's say number one, okay? So for default, we are going to put the value as. Okay? So that means if nothing works, then we want the default value to be printed which is not valid. If it is not between one to file. If the value is one, then what are the activities you want to print?

Something like that. Right. It's the add new case to sorry. Let's do this if it is between one or if it is one or two. Print that message or else it's gonna print not valid. Right, just a quick check.

So in this case, we have saved the program, I just ran it as well. What's the value of number? It's printed as one, I mean, number two is of no use, and it printed one. So, what we could have done the alternative approach, which wouldn't have been a good approach for sure is that you know, we would have used nested f like, you know, if say, if it is equal to one, then print one else in the else itself, we would have said, if it is equal to two, then we would have said, print to else that print invalid. So it would have been like an F inside an F. And if let's say we have to take five use cases the process would have been even more convoluted. So to make that simple, we simply provide the cases in the switch statement and we are able to operate on each and every case.

Whichever holds true because finding value will be displayed or the computations will be performed depending on the value that expression holds. This brings us to the next topic nested activities. nested activities are the ones that are targeted within the same activity type. And in fact to be available within another activity is called nested if similarly, switch activities can reside within other switch activities forming the nested switch. One major point to remember in using nested conditional operations is the scope of each activity. The activities would be evaluated locally first, meaning the sequence of activity under consideration will be evaluated based on the condition validity of the statement within its inner scope and not the outside one.

So, just say we have If we use a nested if statement, so first let's use if condition. And I'm not going to connect it to the workflow yet because I just want to show how it works. And suppose you have number one, let me number one, you want to check if it is greater than number two, right? And within this you have another if condition that says that, you know, if there's another number number three that we have used in our workflow, then say number one is greater than number three, right, which is not there yet. But of course, if there was, then we could have printed the message saying, number one is greatest. Right or else You could have said that, you know, that just although we haven't checked the number three and the number two, but because number one is greater than number two, and number one is integrated than number three in this else statement.

So we could have put the message saying that number three is crest, right? And if we haven't checked, because in this we have only checked number one and number two. So what we can say in here for sure is that number one is smaller than number two, for sure, because we will have to go another if statement to check between number two and number three, and then we will be able to conclude whether number two is greatest or number three is greatest, and which holds the second position as well. So the first thing the second message, this means this and this lies within the scope of nested if activity, while the third message box lies within the scope of the outer if activity scoping is crucial, while using nested activities, and must be thoroughly looked at. A note that we need to maintain in here is that even loops are nested into one another, forming a series of preparatory steps one after the other.

All right, so that's how we use it. But of course, if in any case, you can use the switch statement, I would highly recommend to always go for that. Okay. Next, loops. A loop refers to the repetitive execution of same set of activities, until the conditional expression it holds is not valid anymore. In UiPath, we have three types of loops supported, which are named as while loop, do while loop and for each loop.

This is how we're going to describe each one of them. While loop, a while loop is the most fundamental looping activity within UiPath. It repeats the execution of a sequence of activities, while its controlling expression is true. This is how a general while loop looks like you have a condition. If it is valid, then these statements, the true statements would be executed. And there would be a counter variable which will be updated because every time you don't want to the loop to go on forever.

So let's say there's a condition that says there's a, you want to start a loop or you want to continue with the loop or 10 times. So in that case, if you use a variable which has an initial value of one, then every time you execute the statements, then in here in the counter variable, you'll update that value by incrementing it by one. So the calorie label will now be We'll have a value of two and then again it will go back to the condition and does the variable still holds a value less than 10 Yes. So, again it will be going through the statements executing them and again updating the counter variable and so on. Once it is equal to 10 the counter variable, the condition would not be true because 10 is not greater than 10 it's equal to 10 or so, it will directly go to you know, out of the these true conditions and the rest of the workflow would be executed.

Right the condition results in Boolean output on which further activities are executed. The sequence of activities will keep executing until the condition is valid. And this the sequence of activities is also called the body and this moon more or less like an iteration or modification of the operation using in the being used in the conditional expression. So, let's say Just to give a quick example on while loop II probably don't even need these anymore. So suppose you want to print the value of everything you want to say is number one do we have this in here? Okay.

So, let's say for this number one variable we put it as a default value of one. And the while loop has been like we are putting the values in while loop and we are saying if numbers One is less than five, then keep continuing that means keep continuing with this body of sequence of steps that you're going to ask him to do, we'll simply say that, you know, print a message saying, I'm still valid. Right, it could have been any sequence of activities, there could have been some computation, some addition, some operations, you know, it could have been anything. But just to show how loop works, we're using a very simple example in here. And what it's gonna do is every time the number is less than five, it's gonna print this in the output panel saying that I'm still valid, but we have to increment the value as well.

Otherwise, if you're not changing the value of number one variable, then the loop will be stuck forever. It's gonna keep writing in the output panel and there will be no breaking point for it. So we incremented by using an A Signs statement or any sign activity, and you see automatically sequences created within the body. So you can also say that, you know, why loop activities or something like that just to make it better. And number one is equal to number one plus one. That's how you're incrementing the value by one for that variable.

Right? And you've already connected it looks good, there is no error in terms of the compile ation. So pre check has already been done. And once you run this activity, you see. Yep, it ran. And if we see, I'm still valid, I'm still valid.

I'm still I'm still valid. Guess why it happened only four times because the initial value we gave to the variable was one. So one is less than five. Yes. Then it became the number we came to. So again went three, yes, four years, but it is five the condition was false.

So it went out of the loop and because we don't have any other activities to execute upon the program simply ended by executing the state at this, this particular set of activities, just four times. Okay? So we like a few points, remember in this case is that you know, you have to have a counter variable to make sure that you're, you know, variable that your bleep, your loop doesn't stuck get stuck forever. And you have to use the increment, you have to increment the counter using an assign activity or if there's any other further computation involved. Of course, you have to have some change in your counter variable to make sure that there is a finite number of steps, a finite number of times the sequence of steps would be executed. Okay, next is the do while activity so Dual activity has, it's like pretty similar to wild activity, which was described before.

However, the only thing is that the controlling statement in a while loop, even if it is false, since the beginning of the execution itself, right, the body of the loop will be executed at least once. Why? There are times when we need to execute the sequence of activities listed in a body of a loop at least once. And this is where the do while loop comes into play. The sequence of activities are executed at least initially, first, and then the condition is checked. That's how the structuring of Dubai loop is.

And you can see it in this general expression that I've shown. The first the statements would be executed, the counter variable would be updated, and then it will check whether the condition holds true or not. And then again, we'll go through the statements if the value of the condition is still valid, of course Then the counter variable would be updated, then again condition which at any time the condition is not valid, it's going to go and execute the rest of the workflow. Right. So that's pretty same as a while loop, it's only like a few a very quick difference. So, the last looping activity is for each activity.

This is one of the most commonly used looping techniques in UiPath. In this, the first expression refers to the initialization statement, where the value of a loop control variable is set. This variable acts as a counter variable to control the execution of the repetitive steps provided within the body of the loop. It is worth noting that the initialization expression is executed only once, after initialization comes to the body of the loop. Similar to while and do wild activities, the body consists of sequence of activities that need to be executed against Again adhering to the business logic being implemented. And the for each activity is used to traverse through lists, areas, data tables, collection data types, to process each item within that data structure individually.

And the iteration of the data item within the data structure executes automatically that is, unlike while and do while loops, we don't need to have a separate incrementing activity in these and this is how the general form of this activity looks like. So, in the first step itself, we'll initialize a variable let's say called item and it is gonna traverse through each and every item of a particular list or area or whatever the data structure is in a sequential manner, right one by one. And then Consequently, the operations which are provided in the body section of that activity would be executed once the entire data structure is traversed. The Our program comes out of the loop and executes the rest of the workflow. So being one of the most important activities, let's have a demo on how it looks like. So, let's say here is we have a for each activity in here, and we have a variable called fruit variable, which is an array of string type.

And it has three values Apple, mango, and banana. Right. And in the for each activity, it automatically comes with the counter variable, so you don't need to initialize it in the variable pane. And for each item in this fruit array, we just want to print that item. Right, whatever that item is, the value of the item is, so we'll simply write item.to string. And you can see it's connected.

It's all there. If you run this program Then, in the output panel, we got Apple, mango, and banana all three values are currently like despite all correctly, so, with the for each loop we traverse through the data structure individually, each item of it. And then he performed the computation, the operation are simply displayed for each method is a very, you know, easy to use, most frequently used and like it provides a lot of you know, capabilities in terms of accessing the items to from the data structure itself and working on it and probably, you know, some sort of logic that we may have to implement, let's say, let's say you have a data for all the students in a class who scored some marks in their mathematics test right, then and the thing is that there was some error and everybody needs to Have an increase in their marks by three, something like that just just a hypothetical situation in here.

So you can simply traverse through the whole list, put the whole first of all, put the whole classes math test data, the score data into a variable, and have a tie, and then traverse through each and every item of it by an incremented by three, each item is equal to item plus three, something like that. So a few points remember in for each loop is the initialization of an array within default field of variable pain. Right? If you're doing like this, or even if you were using an assign activity, you have to do it in curly braces. And the items if they're a string type, of course, then you have to put them in double quotes. Or if they were integers, you could have just put them like the actual values itself.

Right. And any data type is always succeeded by square braces. Like string it could have been integer 32 and then these square brackets etc etc and the loop variable which is the scalar variable is typecasted to whatever type the overall list or the array is so that the it becomes displayable for the workflow and it can traverse through the whole list easily right okay. Next is the break activity. So, break activities always used within the for each loop, right. What happens is, once you encounter a break activity, it forcibly terminates the scope of that loop, sidestepping the conditional statement and any code within the body section of that loop.

And when it is executed inside the loop, any remaining activities within that loop are not executed and it right away comes out of the loop. itself. So, a quick example would be say in this itself in this example the one that we just do, where we are traversing through the fruit array data type one by one, you want to check that the first time it you know traverses through the list through the array is the item.to string equals banana right. So, if it is banana, then you want to print, banana or something like that, and if not, you want to print fruit is and by the way if you want to add, you know some variables along with some messages to your right line or to your message box activity. You do the concatenation using a plus sign. So you put it like this fruit is or the fruit is.

Item. Right and so the first you want to check if the first item within the array is Bran or not if it is you want to print banana, if not, you want to print what that fruit is. And let's say you want to break it, simply go to the break automatically the sequences generated no banana or something like that. Right, and you have the whole sequence of activities and once it encounters the break, it will not go execute the loop again, again, it will directly come out of it, which is going to be the end of the workflow in this case. So let's try and run this Here you see, in the output pane, the fruit is Apple and nothing else has been printed, that means the brain activity actually executed successfully and it got us back out of the loop. So, say in some in most of the cases, brain activity is used when you know, you understand that there is no point in going with a loop, you have met some sort of condition.

So, say if you want to check whether a number is prime or not, right, once you've established the fact that it is divisible by any number, you don't want to go through the whole loop again, and again, it's gonna take a lot of your time. You don't you want your program to be as efficient as possible, you want your robot to work as optimally in terms of time as possible. And in that case, he used the brake activity so that once it has been established, that it is not that there are a number that was considering is not a prime number. You just come out of the loop and do execute rest of the activities that are there in the workflow, right. So that's a very good use case of break activity. Before concluding this, I also want to touch to a very high level, another activity, which is a looping activity called for each row.

So for each row activities, it works pretty much like the for each activity. The only catch is that this activity is restricted to only data tables. Right? So in this, the counter variable is going to be your off road type. And they're extensively used while dealing with Excel or CSV files. And this activity executes a sequence of actions enclosed within the body section for each row in the data table provided to it as the input.

Right so we don't have a database yet because we haven't discussed that in thoroughly. But we will be discussing that in our subsequent chapters because major file when we're reading data from files like Excel or CSV, which is going to be Like one of the major use cases for any bot to work on, then we'll be dealing with data tables. So, but just say if you had some data table called employee the employee data table right? And you want to traverse through it and you want to print like in this employee, let's say you have name class section and and their employee IDs, their salary and all that information, and you want to print just their names just for an example sake, right. Then what you can use is a statement like this row, right? And in the brackets itself, you can give the column name, let's say name, in this case, and then you want to always change it to string because force the it has to be made the label in the workflow.

And that's how the data can be the argument for the column name can be passed within itself. There are like a lot of other ways that you know, you can use it like say, if you want to filter, filter these rows based on some conditions, then you can actually use the SQL script or the SQL queries to filter out only those rows which you want to display. And the possible cases are that you know, you may want to let's say, write that whole data into another excel sheet, which is going to be our output excel sheet output CSV or you just want to display it or there could be some other further computations like once you have got some filtered rows, you want to check who among these people actually hold a very senior title or a salary more than hundred thousand dollars or something like that.

So for the competition's could also be involved, but data tables and budget travel Through the data tables, we have to use this looping activity which is called for each row. So this is pretty much what covers the data operations. And we'll be dealing with all these concepts in our subsequent chapters. So I'd highly recommend that you go through them once and understand them practice them. And if there are any concerns, understand the theory, try out new and different functions, like for the string for integers for, for anything, for for Boolean, also, you should definitely give it a shot for generic you can check if the implicit conversion between two different data types is happening or not if it is successful or not. And just keep practicing because you get a very good hold of this and it comes like it comes as very advantages in the subsequent chapters.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.