4D v16.3If...Else...End if |
||
|
4D v16.3
If...Else...End if
If...Else...End if
The formal syntax of the If...Else...End if control flow structure is: If(Boolean_Expression) Note that the Else part is optional; you can write: If(Boolean_Expression) The If...Else...End if structure lets your method choose between two actions, depending on whether a test (a Boolean expression) is TRUE or FALSE. When the Boolean expression is TRUE, the statements immediately following the test are executed. If the Boolean expression is FALSE, the statements following the Else statement are executed. The Else statement is optional; if you omit Else, execution continues with the first statement (if any) following the End if. Note that the Boolean expression is always fully evaluated. Consider in particular the following test: If(MethodA & MethodB) The expression is TRUE only if both methods are TRUE. However, even if MethodA returns FALSE, 4D will still evaluate MethodB, which is a useless waste of time. In this case, it is more interesting to use a structure like: If(MethodA) The result is similar and MethodB is evaluated only if necessary. ` Ask the user to enter a name Tip: Branching can be performed without statements to be executed in one case or the other. When developing an algorithm or a specialized application, nothing prevents you from writing: If(Boolean_Expression) or: If(Boolean_Expression)
See also
Case of...Else...End case
|
PROPERTIES
Product: 4D
HISTORY
ARTICLE USAGE
4D Language Reference ( 4D v16) |