Gentee Programming Language > Documentation > Syntax Download documentation

The Conditional Operator ?

The conditional operator ? operates in the similar way as the if-else statement, but the conditional operator can be located in the expression. The operator is a ternary operator (it takes three operands). The operands separated by commas are enclosed in parentheses; the first logical (integer) expression is evaluated. If the value is nonzero (TRUE), the second expression will be evaluated, the value of which will be a result of the conditional operation. Otherwise, the third operand will be evaluated, the value of which will be returned.

<question> ::= '?''(' <expression>',' [<expression>] ',' [<expression>] ')'

r = ?( a == 10, a, a + b ) // If a = 10, then r = a, else r = a + b

See also

    Table Of Operator Precedence


 Copyright © 2004-2006 Gentee Inc. All rights reserved.