MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

The Branch Statement in esProc

Published on 10 September 14
0
0
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.
The Branch Statement in esProc - Image 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:
The Branch Statement in esProc - Image 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.
The Branch Statement in esProc - Image 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.
The Branch Statement in esProc - Image 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.
The Branch Statement in esProc - Image 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:
The Branch Statement in esProc - Image 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.
The Branch Statement in esProc - Image 7

5 .The Nested Branch Statement

Branch statement can be used to make further judgment in the code block of if or else.
The Branch Statement in esProc - Image 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:
The Branch Statement in esProc - Image 9
This blog is listed under Development & Implementations Community

Related Posts:
Post a Comment

Please notify me the replies via email.

Important:
  • We hope the conversations that take place on MyTechLogy.com will be constructive and thought-provoking.
  • To ensure the quality of the discussion, our moderators may review/edit the comments for clarity and relevance.
  • Comments that are promotional, mean-spirited, or off-topic may be deleted per the moderators' judgment.
 
Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top