| View previous topic :: View next topic |
| Author |
Message |
tuna
Joined: 03 Oct 2007 Posts: 155 Location: UK
|
Posted: Tue Oct 28, 2008 6:16 am Post subject: Ternary Operator Documentation |
|
|
It's not a major issue but it's caused me enough confusion to report this. The documentation of the use of the ternary operator is inconsistent as sometimes it is | Code: | | x := foo > bar ? true : false ; correct use | and at other times is | Code: | | x := foo > bar ? false : true ; incorrect use |
It crops up from place to place in examples:
| Quote: | The ternary operator is also a good candidate: | Code: | ProductIsAvailable := (Color = "Red")
? false ; We don't have any red products, so don't bother calling the function.
: ProductIsAvailableInColor(Product, Color) |
|
though the description of the ternary operator itself is correct:
| Quote: | | For example, var := x>y ? 2 : 3 stores 2 in Var if x is greater than y; otherwise it stores 3 |
Many thanks |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Oct 28, 2008 6:46 am Post subject: Re: Ternary Operator Documentation |
|
|
No, the examples you cite are correct. | Code: | ProductIsAvailable := (Color = "Red")
? false ; We don't have any red products, so don't bother calling the function.
: ProductIsAvailableInColor(Product, Color) |
Explanation: if color=red (TRUE), return FALSE, else return TRUE. So after evaluation the 'if' will fail (FALSE) if color=red.
For good explanation of the Ternary operator see http://tinyurl.com/4ujg6q |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Tue Oct 28, 2008 7:07 am Post subject: Re: Ternary Operator Documentation |
|
|
| tuna wrote: | The documentation of the use of the ternary operator is inconsistent as sometimes it is | Code: | | x := foo > bar ? true : false ; correct use | and at other times is | Code: | | x := foo > bar ? false : true ; incorrect use |
|
Both of these are perfectly valid examples, just with opposite results.. |
|
| Back to top |
|
 |
tuna
Joined: 03 Oct 2007 Posts: 155 Location: UK
|
Posted: Tue Oct 28, 2008 7:10 am Post subject: |
|
|
sorry - my bad - its getting to late for this...  |
|
| Back to top |
|
 |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Tue Oct 28, 2008 9:05 pm Post subject: |
|
|
in case u want to use just true and false as direct assignments you can also use this ternary
greets
dR _________________
All scripts, unless otherwise noted, are hereby released under CC-BY |
|
| Back to top |
|
 |
|