t3x.org / t3x / t3x-manual / 268.html
 
T3X - A Minimum Procedural Language
Version 8.1.5, Online Edition
Copyright(C) 1996-2004
Nils M Holm
 
Previous:
2.6.7 Conjunctions and Disjunctions
TOC | Index | Back Next:
2.6.9 Constant Expressions

2.6.8 Conditional Expressions

The ternary conditional operator has the least precedence. Therefore, it may be used to combine any kind of expressions without using parentheses. The following expression, for example, implements the minimum function:

a<b -> a : b

Since the operator has three operands, it consists of two parts: '->' and ':'. The meaning of the conditional operator is as follows: Given is the expression

A-> B: C

If the operand A (the condition) evaluates to some `true' value, B will be evaluated and otherwise, C will be evaluated. If B is evaluated, C will not be evaluated and vice versa. The result of the expression is equal to the value of the most recently evaluated operand.

Like the logical operators /\ and \/, the conditional operator has a connection to conditional statements:

A-> B(): C()

is equivalent to

IE (A) B(); ELSE C();

except for the fact, of course, that the expression has a value, while the statement only has a side effect. IE means If/Else and introduces a conditional statement with an alternative. The IE statement will be discussed in a later section.

Previous:
2.6.7 Conjunctions and Disjunctions
TOC | Index | Back Next:
2.6.9 Constant Expressions