FAQ Database Discussion Community


Does haskell have a conditional operator such as “x == y ? a : b” in C++ or ifelse(x==y, a, b) in R?

haskell,conditional-operator
Does haskell have a conditional operator that performs as x == y ? a : b in C++ or ifelse(x==y, a, b) in R ?...

How to convert PHP ternary expression to if-else?

php,if-statement,conditional-operator,code-conversion
I've following snippet of code that is written using conditional operator : $iPage=($this->request()->get('search') ? $this->request()->getInt('req4') : ($this->request()->getInt('req3') ? $this->request()->getInt('req3') : 1 )); I converted this into if-else format as follows : if($this->request()->get('search')) { $this->request()->getInt('req4') } else { ($this->request()->getInt('req3') } Would someone please help me in telling that whether I've made...

Incompatible types in conditional expression when casting

c,pointers,casting,conditional-operator,kernighan-and-ritchie
I'm currently working my way through the K&R exercises, and there's something that's bugging me. I have the qsort function declaration: void qsort(void *v[], int left, int right, int (*comp)(void *, void *)); According to the book, I should be able to use the conditional expression to choose the compare...

Finding the last occurrence of text in a column to result in adjacent cell value

excel,if-statement,boolean,conditional-operator
This is the current formula that works well when copied down, but now I want the false value to no longer be "", and instead be the value that is 2 columns adjacent to it. =IF(OR(F2="Craps",F2="$$$",F2="PtEst"),"ComeOut","") For instance, when this formula is in cell G3, I want it to return...

casting inside conditional operator in Java

java,eclipse,list,casting,conditional-operator
This give an error in eclipse IDE.(Error symbol appearing near the line number) String[] allText = null; After this i have done some stuff like initialing the array and so on. But according to some conditions. So I want to use a conditional operator like below. List<String> finalText = (allText...

Conditional Operators in C#

c#,asp.net,conditional-operator,comparison-operators
I am trying to compare two values from a label and textbox. When the AvailQty is at 6 it is considered to be "Low" and if a user types in 4 or 10 it will display error because there's only 6 available. I have this: if ((Int32.Parse(AvailQty.Text) <= 6) &&...

Ternary operator in C vs C++ [duplicate]

c++,c,ternary-operator,conditional-operator
This question already has an answer here: Errors using ternary operator in c 4 answers There are a lot of differences between C and C++ and came to stuck on one of them The same code gives an error in C while just executes fine in C++ Please explain...

Javascript one line If…else…else if statement

javascript,conditional-operator
I know you can set variables with one line if/else statements by doing var variable = (condition) ? (true block) : (else block), but I was wondering if there was a way to put an else if statement in there. Any suggestions would be appreciated, thanks!

JavaScript short circuit evaluation error?

javascript,conditional-statements,conditional-operator,typeof,short-circuiting
The two below snippets of JS code have had me confused, in my eyes both should work the same, due to short circuit evaluation. But for some reason snippet '1' causes the error (on the third line): Cannot read property 'match' of undefined Array 'a' holds 3 character values user...

javax.el.PropertyNotWritableException when using EL conditional operator in value of UIInput

jsf,input,el,placeholder,conditional-operator
I get this error message: javax.el.PropertyNotWritableException: /u/editProfile.xhtml @64,140 value="#{empty userProfile.cfg.gpu or userProfile.cfg.gpu == '' ? usernavmsg.EditMe: userProfile.cfg.gpu}": null The problem is that when the value of a bean property is null the value of an inputText field switches from my ManagedBean property, to a resource string. So I cannot persist...

Does F# have the ternary ?: operator?

f#,conditional-operator
I'm learning F# coming from C# and I've just tried compiling an expression like let y = Seq.groupBy (fun x -> (x < p ? -1 : x == p ? 0: 1)) but see 'unexpected integer literal in expression'. Does F# have a ternary operator? If not, what should...

Why doesn't Swift nil-coalescing ternary operator return unwrapped type?

swift,conditional-operator
I read that the ternary operator ?? unwraps an optional if it is not nil, but if I do: var type: String? type = "milk" let certainType = type ?? "melon" then certainType will still be a String?, and if I do println("it's a \(certainType)") it will print: it's a...

Conditionally rendering component sections in React JSX

javascript,reactjs,conditional-statements,conditional-operator,react-jsx
According to MDN "You can also do more than one single operation per case, separating them with a comma." The example below works: var stop = false, age = 23; age > 18 ? ( alert("1"), alert("2") ) : ( stop = true, alert("Sorry, you are much too young!") );...

“Most important const” with conditional expression?

c++,conditional-operator
Consider the following code: int foo(MyClass const* aPtr = 0) { MyClass const& a = aPtr ? *aPtr : MyClass(); // Either bind to *aPtr, or to a default-constructed MyClass ... return a.bar(); } The "most important const" is, hopefully, being used here. The aim is to allow for a...

Java switch - varying conditional operators

java,if-statement,switch-statement,conditional-operator
I found a few "somewhat" related questions on this, but I'm not confident that my needs have been fully qualified in those questions. So, what I'm looking to do is to clean up the following IF/ELSE IF statement with a SWITCH/CASE. Is there a way to use multiple conditional operators...

Conditional Operator in F# (A?B:C) [duplicate]

c#,f#,conditional-operator
This question already has an answer here: Does F# have the ternary ?: operator? 3 answers In C#, we have the conditional operator: [condition] ? [value if true] : [value if false] But I can't seem to find this in F#. Does it exist?...