Use the Conditional Expressions "if" and "else" as a general expression evaluator to see if it equates to true (non-zero) or false (zero). If the expression equates to true, then the block associated with the "if" is executed. If the expression equates to false, then the block associated with the "else" is executed. The "else" part of the expression is optional.


Example:


set a=10;

if ($a<10) {

echo "a is less than 10";

} else {

echo "a is greater than or equal to 10";

}


This will echo "a is greater than or equal to 10"


You can also use "C-Style" conditional expressions to check if a variable equates to zero (false) or non-zero (true);


set a=0;

set b=1;

if ($a) {

echo "this will not echo";

}

if ($b) {

echo "this will echo";

}


NOTE:  in DMScript the braces are mandatory when constructing a conditional expression, even if there is only one statement to execute.


If can also be used to filter the current Endpoint list. For example, an Environment may contain 10 Endpoints. The Endpoint list is this complete list of Endpoint associated with the Component on the stack. You can use the if expression to reduce this list to Endpoints matching the specified criteria. For example, if you use IF with an expression of ATVAL=’Y’ then any code attached to the then part of the if will operate only on Endpoints with an attribute of ATVAL that is equal to Y. Similarly, any actions attached to the else part of the if statement will operate only on Endpoints without an attribute of ATVAL or with an ATVAL attribute that is not equal to Y.


When using an if expression in this way, both the then and else parts can be executed with different server sets in each block.


Example:


if ($HAS_MY_SERVICE = "Y") {
 // this block only executes for Endpoints

 // with the HAS_MY_SERVICE attribute set to "Y"

 servicectl($SERVICE_NAME,"stop");                // stop the service
}