![]() |
![]() |
|
| Home I Company I Services I Documentation I Downloads I E-Support |
| home -> documentation -> environment guide -> Making decisions: The IF tag | |||
|
Making decisions is a fundamental concept in the most of the web applications. We need to take decisions of what options or information we need to present to the user. Thus, we need the ability to make comparisons between variables, constants and expressions. So, the first step is to learn how to make comparisons.
As we see in the Section 6.6, some DBSP elements have the ability to evaluate arithmetic operations using the EXPRESSION property. However, the evaluator is not restricted to arithmetic operations only; it could evaluate Boolean expressions resulting in true or false. These expressions will be the basis of the decision taking in our systems. See the EXPRESSION documentation for more information about this property.
The IF Tag condition a block of code to the result of a comparison, defined in the expression property. If the result is TRUE, the block is inserted; otherwise it is not. The IF Tag, in its simplest configuration, is of the form:
where the EXPRESSION property must be a Boolean expression.
We can extend the basic IF Tag by adding an ELSE tag before the IF closing tag. This tag provides a second block choice, when the result of the expression is false. The syntax of this tag is of the form:
This provides an explicit choice between two courses of action - one if the if expression is true and another for when it is false.
The block code executed when an IF tag is true can contain another IF tag, in the IF or ELSE block. An IF tag that is nested inside another, can also itself contain a nested IF. There is no limit on the number nested IF tags. However, is not the best practice because it adds confusion to the application logic. Here is an example of a nested IF tag
Even when multiple decision branches could be taken with nested Ifs, there is a much simpler way to achieve the same result, as we will see in the next section.
Example 1. A simple IF tag This example shows the most basic use of the IF Tag. Source code
Test example
Source code
Test example
Source code
Test example
|