The Branch Statement in esProc

In branch statement, we need to check one or multiple conditions, execute different code according to the results or return different results. In esProc, the branch statement if/else has the following form:

1.if x … else … at the same line

When condition x after if is true, execute the statement after it. Otherwise execute the statement after else. The else part can be omitted, else and if must be in the same row. After execution, the value of the cell in which if is located is the computed result of x.

esProc_branch_1

Sometimes, there is no else part, we only need to decide whether the code after if statement should  be executed:

The below logical connector can be used in the judgment statements:

esProc_branch_2

  • a&&b

For the “a and b”, the result is true only on condition that both a and b are true.

  • a||b

For the “a or b”, the result is true only on condition that either a or b is true.

  • !a

For the “not a”, the result is true only on condition that a is false.

esProc_branch_3

2. Function if(x,a,b)

When x is true, compute expression a and return the result; otherwise, compute expression b and return the result. Sometimes, the previously mentioned if…else… code can be replaced by function if in order to make the statement more concise.

esProc_branch_4

3. if x … else … in the code block

If x is true, then execute the code block of if; otherwise, execute the code block of else. You can certainly ignore the else part. else and if must be in the same column. Different from some other program languages, esProc employs code block, in stead of symbols such as {} or statements like end if, to determine the statement’s valid scope.

esProc_branch_5

As shown in the example, code block of if, or code block of else, is executed alternatively based on the judging results of B4 to compute the name list and total number of male employees, as well as those of female employees. Results can be seen in B2, B3, C2 and C3 after the computations are over:

esProc_branch_6

4.Multiple blocks of if x … else if y …

This is code for multi-branch statement in esProc, which can be written repeatedly forever. If x is true, then execute the code block of if; otherwise, if y is true, execute the code block of else if…., else and if must be in the same cell. Again the point is emphasized that there is no such corresponding statement of end if, and esProc employs the scope of code block to determine when if statement will be over.

esProc_branch_7

5.The Nested Branch Statement

Branch statement can be used to make further judgment in the code block of if or else.

esProc_branch_8

In the above example, a character string of year and month, with a separator “-”, is input in A1, and the code after it computes the total days of the month. The computation should first judge which month it is. For February, further judgment is needed to determine whether it is a leap year. The computed result in A8 is as follows:

esProc_branch_9

 

Advertisements

About datathinker

a technical consultant on Database performance optimization, Database storage expansion, Off-database computation. personal blog at: datakeywrod, website: raqsoft
This entry was posted in Program Language and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s