1. if x … else … at the same line
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:
Ø 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.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.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.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:
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.5 .The Nested Branch Statement
Branch statement can be used to make further judgment in the code block of if or else.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:
没有评论:
发表评论