Flow Control

It can often be both beneficial and necessary that you are able to check the progress of your procedures in a structured way. As in all other forms of logic and programming, we distinguish in SeqZap between conditional structures and loop structures.

A conditional structure is used to make choices, for example if a variable has a certain value, if a switch is on or off, if a measurement exceeds a certain value etc., while a loop structure is used to repeat all or part of your procedure until a certain condition is met one or a specified number of times.

Let us begin with an example of how to insert a conditional structure in a procedure in which the procedure must do one thing if it is a weekday and otherwise do something else:

1 Right-click on the line where you wish to insert your al and select the command Insert Step ( Flow Control ( IF in the shortcut menu.

The beginning of a conditional structure.

SeqZap then inserts two lines in your procedure. The IF statement itself is the first part of the conditional structure and is used to define the condition to be used to direct you to the right place in the procedure, and since all structures have both a beginning and an end, the conditional structure will close with an END-step.

NOTE Remember that the condition should give the value TRUE or FALSE which is written through comparison operators such as ==, >, <, >=, <= and !=. The latter operator means different from, which you might know as <> in for example Microsoft Excel, but in SeqZap it is written as an exclamation mark and an equals sign. The reason for this is that we, as mentioned previously, follow the spelling of the high-level languages such as C++ and C#, where an exclamation mark means NOT, and != is thus read as not equal.

2 Type your condition either directly in the document window or by using the field Expression in the properties window.

In this simple example we want to know what day it is, and then respond to whether it is a weekday or a weekend. We therefore use the function dayOfWeek (), which returns an integer number from 0-6 to tell what day it is. Day 0 is Monday and so forth, why day 5 and day 6 then are respectively Saturday and Sunday (we have assumed that if it is not a weekday, it must be a weekend).

Example of a very simple IF-condition.

Notice that the fields Log text on TRUE and Log text on FALSE can write a text that, depending on the result of your condition, is written in your execution log but is not used in the actual procedure.

TIP If you do not want to sit and wait for it to become weekend to see if the IF-condition is working, you can instead try to write DayOfWeek(DateTime(2013,01,05,12,00,00)) <= 4 as a condition (the date of the first Saturday of 2013). The function DateTime() is used to return a date from integer values ​​respectively for the year, month, date, hour, minutes and seconds.

Right now, the procedure is not doing anything else besides running the IF-condition and checking what day it is, we must therefore add a few more steps to the conditional structure to see the results of the test.

Let us try to use a few Log Comment steps to illustrate, however we could easily also have used a call procedure or a Set Verdict step as an example.

3 Right-click on the line where you wish to insert a log comment - in this case line 2, which contains our END-step, and select the command Insert Step ( Log Comment in the shortcut menu.

Type the text that you want to have displayed in the execution log if the condition in the IF-comment evaluates to TRUE.

TIP Remember that all text in SeqZap must be written in double quotation marks.

The result is now displayed as a log-comment in the execution log.

If you run this procedure during a weekend, nothing will be written to the log - unless you have specified this in the property sheet for the IF-condition. If you want your procedure to handle this itself, especially if certain steps are to be performed on the weekends, you need to add an ELSE step to your conditional structure.

4 Right-click on the last line in your conditional structure, in this case line 3, and select the command Insert Step ( Flow Control ( ELSE in the properties window.

If the condition in your conditional structure is TRUE, the procedure will skip line 2 and move on in your procedure.

5 Right-click again on the last line in your conditional structure and select the command Insert Step ( Log Comment in the shortcut menu to insert a comment in your execution log if the IF condition is evaluated to be FALSE.

Example of an IF-ELSE structure.

You have probably noticed that there also exists an ELSE IF step. You can use this to find out whether it is a Saturday or a Sunday instead of just knowing that it is weekend.

6 Right-click on the line where you wish to insert an additional condition in the same conditional structure, in this case line 3, and select the command Insert Step ( Flow Control ( ELSE IF in the properties menu.

7 Type the new condition in the ELSE IF-step the same way as in the IF condition.

8 Right-click on line 4 and select the command Insert Step ( Log Comment in the properties menu to insert a new log comment under the ELSE IF-step.

The finished condition structure.

9 Adjust the test in the last log comment so that it fits into the logic of your conditional structure.

In this example, we do not exactly follow the so called best practice, since we ask for the same value twice – in this case by using the DayOfWeek() function. Partly because it takes time, although it is quite a short time, but worse is the fact that the value may have changed along the way. In this case, it could be that you have executed the procedure around midnight, but in other cases it could be that you asked for the value of a switch, a measurement or the like, and it has changed between the two queries.

It is best practice that you save the value of the measurement or the like in a variable, which you then can evaluate multiple times without it changing values along the way.