Maptitude GISDK Help

If Statements

 

The if statement executes a single statement or a group of statements if an expression evaluates to True. The if statement can also be used with the else clause, which contains one statement or a series of statements to execute if the expression evaluates to False. The do and end clauses are used to mark the beginning and end of a group of statements, and can be omitted if only a single statement is to be executed as the result of an if or else.

 

The following are valid forms of the if statement:

 

if expression then statement

 

if expression then do

     <one or more statements go here>

     end

 

if expression then statement else statement

 

if expression then do

     <statements go here>

     end

else statement

 

if expression then statement

else do

     <statements go here>

     end

 

if expression then do

     <statements go here>

     end

else do

     <statements go here>

     end

 

For example:

 

if GetLayer() = "States" then

     // Only a single statement; no do or end required

     ShowMessage("The current layer is States")

else do

     // Do and end MUST be used

     ShowMessage("I'll fix the current layer...")

     SetLayer("States")

     end

 

An If statement can be used as a conditional expression. For example:

 

message = "The number is " + (if number<0 then "negative" else "positive")

 

Evaluation of If Expressions

It is best to enclose If statements in parentheses, because they are evaluated at the lowest precedence. If the else clause is omitted and the condition is false, the resulting value is null.

 

The expression evaluates to true if it is any of these values:

 

"Yes", "True", 1, "On", true

 

The expression evaluates to false if it is any of these values:

 

"No", "False", null "Off", false

 

Maptitude evaluates Boolean expressions and If expressions with "lazy" evaluation or what is sometimes called "conditional" operations. For more information on the evaluation of Boolean expressions, see Logical Operators. The If expression

 

x = if a then b else c

 

will always evaluate a but, depending on the result, it will only evaluate one of b or c, but not both. More complicated nestings of Boolean expressions and If expressions will all do the minimum evaluation possible. This should allow for simpler programming. For example,

 

if x = null or x[1] = null then ...

 

will no longer give an error if x is null. More importantly, you will be able to fill formulas with If expressions and get the expected result. For example, the expression

 

if X=0 then 1.0 else Y/X

 

will no longer evaluate to null (missing), for records with X equal to zero, because of the zero-division error that used to occur when evaluating the else part.

 

 

©2025 Caliper Corporation www.caliper.com