select chapter

laiye rpa developer guide d1-凯发网站

we have learned that a block usually contains multiple commands. in the examples earlier, the commands in a block are executed one after another. for example, a block for writing data into an excel file has four commands—open excel file, read cell, save excel, close excel—, and it executes them one by one. this structure of executing commands one by one is called a sequential structure. however, in practice, there are often scenarios that call for structures beyond a sequential one. in this chapter, we will introduce more complicated structures and how to use logic control to implement these structures in laiye rpa.

let's first introduce a conditional structure. as the name suggests, this structure branches into multiple directions based on how a specified condition evaluates when the process reaches this structure. if the condition is satisfied, then the process will execute one branch. otherwise, the process will execute the other.

in the command area of laiye rpa creator, insert the conditional command under basic commands – grammar to create a conditional.


figure 71: conditional command

in laiye rpa's assembly area, we can visualize the logic of a conditional. the branch that executes when the conditional is satisfied reads if "condition", then, and the area below indicates to us that we can insert commands there. let's insert an output debug information command that outputs "this message is printed if the condition is true." the branch that executes when the conditional is not satisfied reads else, and the area below indicates that we can insert commands there as well. let's insert an output debug information command that outputs "this message is printed if the condition is false." now, the assembly area should look like figure 72.


figure 72: conditional branch command - add output debugging information

let's look at another important structure, a loop structure. a loop structure instructs the process to execute cyclically according to certain rules. different loop structures can be classified into count loops and conditional loops. in fact, there are also two special types of count loops that iterate through arrays and dictionaries, respectively, but since we have not introduced arrays and dictionaries yet, we will leave these loops for later.

let’s look at the count loop first. in the command area of laiye rpa creator, insert the count loop command under basic commands – grammar to create a count loop. insert an output debug information command in the loop body and configure it to output the index name i.


figure 73: count loop

what exactly is the index? by inspecting property panel of the count loop command, we note that it has an index name, which we store as variable i, that counts the number of times we have iterated through this loop, and we can reference this variable inside the count loop. the start value and end value properties define the range of the loop, and the step value defaults to 1. all these values combine to instruct: initialize i as the start value, increment by the value of step every iteration of the loop, until i is greater than the end value, in which case the loop is over. by running this command, we can see that the values 0 to 10 are printed, with a total of 11 numbers.


figure 74: property of count loop

let's look at the condition loop. insert a conditional loop command from basic commands – grammar to create a condition loop. insert an output debug information command in the loop body with the output content "condition is true. continue loop."


figure 75: condition loop

condition loop has the same properties as conditional. they both only have the condition property. the loop will continue only if the condition evaluates to true. in order to make the loop run, we fill in true for the condition.


figure 76: condition loop

when running this command, we find that the loop continues indefinitely, and the string "condition is true. continue loop." is repeatedly outputted. here, we need to click the stop button on the laiye rpa creator toolbar to interrupt the process. keep in mind that a condition loop checks if the provided condition is true every iteration and continues looping until the condition is false. since we provided a fixed boolean value true for condition, this value will always evaluate to true, and the loop will never stop.

there are two ways to resolve this problem. first, laiye rpa provides a suite of commands that allows you to leave a loop, such as continue loop, break loop, break and return, and exit process. we’ll introduce them in the next section. second—this is the more common solution—instead of entering a fixed value, you can enter an expression as the condition. initially the condition can evaluate to true, but as the loop runs, the variables inside the expression change and eventually reach a state where the condition evaluates to false. then, the loop will be terminated.

for example, define a variable a and assign it an initial value of 1. then, set the condition of the loop a<5. initially, this condition is true (since a=1). however, let’s insert a command in the loop that increments a by 1. thus, after a few iterations of the loop, a's value will be no longer smaller than 5, and the loop will terminate.

whether you are using a count loop or a condition loop, the loop body is a command block. we can place zero, one, or many commands inside a command block, and these commands will be executed sequentially. you can even insert conditional commands or other count loop or condition loop commands inside a command block. in other words, logic control commands can be nested. keep this in mind.

as mentioned in the previous section, laiye rpa provides a variety of commands for jumping out of the loop, including continue loop, break loop, break and return, and exit process. some of these commands can be used not only for jumping out of the loop, but also for exiting blocks and entire processes. let’s go through them one by one.

the continue loop command is used inside a loop body to skip to the end of the current loop and continue looping (including checking if the condition still holds, executing the loop body, etc.).


figure 77: continue loop

the break loop command is used inside a loop body to break out of a loop, skipping to the next command after the loop command.


figure 78: break loop

the break and return command can be used to break out of a loop and terminate the current block, returning a given value (named as retvalue by default).


figure 79: break and return

finally, the exit process command can be used to break out of everything and terminate the entire process.


figure 80: exit process

in fact, the break and return and exit process commands can be used not only in a loop body, but anywhere inside a block. therefore, you can terminate the current block or process wherever it suits your needs.

网站地图