Difference between revisions of "IF a THEN b ELSE c"

Line 5: Line 5:
  
 
This conditional expression returns '''b '''if '''a '''is true (1) or '''c '''if '''a '''is false (0), for example:
 
This conditional expression returns '''b '''if '''a '''is true (1) or '''c '''if '''a '''is false (0), for example:
 +
:<code>Variable X := 1M</code>
 +
:<code>Variable Y := 1</code>
 +
:<code>IF X > Y THEN X ELSE Y &rarr; 1M</code>
  
:'''Variable X := 1M'''
+
returns the larger of <code>X</code> and <code>Y</code>.
  
:'''Variable Y := 1'''
+
It is possible to omit the <code>ELSE</code> clause:
 +
:<code>IF X > Y THEN X</code>
  
:'''IF X > Y THEN X ELSE Y &rarr; 1M'''
+
If the condition is false, it gives a warning. If you ignore the warning, it returns <code>NULL</code>.
 
 
returns the larger of '''X '''and '''Y'''.
 
 
 
It is possible to omit the '''ELSE '''clause:
 
 
 
:'''IF X > Y THEN X'''
 
 
 
If the condition is false, it gives a warning. If you ignore the warning, it returns '''NULL'''.
 
  
 
Conditional expressions get more interesting when they work on arrays. See [[IF a THEN b ELSE c with arrays]].
 
Conditional expressions get more interesting when they work on arrays. See [[IF a THEN b ELSE c with arrays]].

Revision as of 13:25, 7 September 2015


Analytica User Guide > Using Expressions > IF a THEN b ELSE c

This conditional expression returns b if a is true (1) or c if a is false (0), for example:

Variable X := 1M
Variable Y := 1
IF X > Y THEN X ELSE Y → 1M

returns the larger of X and Y.

It is possible to omit the ELSE clause:

IF X > Y THEN X

If the condition is false, it gives a warning. If you ignore the warning, it returns NULL.

Conditional expressions get more interesting when they work on arrays. See IF a THEN b ELSE c with arrays.

See Also

Operators <- IF a THEN b ELSE c -> Function calls and parameters
Comments


You are not allowed to post comments.