Joe Bar
1st June 2005, 15:42
Bonjour
What does mean this expression:
tdpur041.pric ? tdpur041.pric : tdpur041.amta
cvat.amount <> 0 ? true : false
edi.gen ? EDI_COPY_TEXT : ""
Thank you for your help
günther
1st June 2005, 16:00
In general, these kind of "question mark expressions" have the syntax:
<condition> ? <expr_1> : <expr_2>
If the condition is TRUE expr_1 will be executed, if the condition is FALSE expr_2 will be executed.
So your example mean:
1. (result =) tdpur041.pric ? tdpur041.pric : tdpur041.amta
double result
if tdpur041.pric <> 0 then
result = tdpur041.pric
else
result = tdpur041.amta
endif
2. (result =) cvat.amount <> 0 ? true : false
long result
if cvat.amount <> 0 then
result = true
else
result = false
endif
| Hm, hm!
| This is identical to:
result = cvat.amount <> 0 |...
3. (result =) edi.gen ? EDI_COPY_TEXT : ""
string result(999)
if edit.gen then
result = EDI_COPY_TEXT
else
result = ""
endif
Joe Bar
1st June 2005, 16:06
Thank you very much.
I supposed that it was that and you confirm it.
Thank you again
Denis
NPRao
2nd June 2005, 00:18
Academic Info -
Ternary operation
In mathematics, a ternary operation is any operation of arity three, that is, that takes three arguments. A ternary operator (sometimes inaccurately referred to as a tertiary operator) is an operator that takes three arguments. A common form found in many programming languages is an operator that is used as shorthand for if-then-else statements. The general form is condition ? op1 : op2. If condition is true, the statement evaluates as op1; otherwise, it evaluates as op2.
In programming, especially in the C programming language, the "?:" operator is a ternary operator.
It takes in a boolean value, and two statements, and returns the return value of the first statement if the boolean value is true, and the return value of the second statement if the boolean value is false.
For example, the statement z = (x > y) ? x : y; assigns x to z if the value x is greater than y, and otherwise assigns y to z (the statement sets z equal to the maximum of x and y).
Some programmers regard using this ternary operator as bad practice, though it can be useful in certain circumstances to avoid excessive if statements.
Reference Link - Ternary Operation (http://www.answers.com/topic/ternary-operation)
günther
2nd June 2005, 09:01
Thanks for the academic part! I've been using ?: for about 15 years (since I come from C) but I did not remember the fact that mathematicians also tend to use short terms ...
Günther