conditional-operator

What happens when you have a conditional operator and a postfix conditional in the same Perl statement?

Can anybody explain how this line works? return $y < 0 ? - pip2 : pip2 if $x == 0; if $y <0 it returns -pip2, but what it returns when $y >= 0 and $x != 0 ? This line is from this function: sub _atan { my( $y, $x ) = @_; return $y < 0 ? - pip2 : pip2 if $x == 0; return atan( $y / $x ); } ...

if(condition, then, else) in Oracle

Hey all, MySQL/MSSQL has a neat little inline if function you can use within queries to detect null values, as shown below. SELECT ... foo.a_field AS "a_field", SELECT if(foo.bar is null, 0, foo.bar) AS "bar", foo.a_field AS "a_field", ... The problem I'm running into now is that this code is not safe to run on an Oracle database,...

why do we prefer ? to ?? operator in c#?

I recently found that we can use ?? operator to check nulls. Please check the below code samples: var res = data ?? new data(); This is exactly similar to var res = (data==null) ? new data() : data ; I checked my whole project source repository and some of other open source projects. And this ?? operator never been used. I ...

conditional operator shortcut in PHP?

Does anybody know if there is a shortcut for the following statement in PHP? $output = isset($some_value) ? $some_value : "Some Value Not Set"; echo $output; This something that I often run into, where $some_value is actually very long and possibly involves a function, such as: $output = $this->db->get_where('my_db',array('id'=>$id))...

Comparison of conditional statements.

Are following ways are same.(Considering the evaluation time) if(Condition1) { //code1 } else { //code2 } condition1 ? code1 : code2 Are they just syntactically different? It may seem a stupid question.But I want to clear my doubt. ...

javascript if alternative

what does this bit of code represent? I know its some kind of if alternative syntax .. pattern.Gotoccurance.score != null ? pattern.Gotoccurance.score : '0' tnx QUESTION UPDATE : why need for this sort of coding, is this more efficient or just shortened version with same efficiency? ...

Odd Perl conditional operator behavior

I'm doing some work in Perl and I ran across an odd result using the conditional operator. The code in question: ($foo eq "blah") ? @x = @somearray : @y = ("another","array"); Trying to compile this code results in the error "Assignment to both a list and a scalar at XXX line YY, near ');'". In trying to pinpoint the source of the er...

What's the difference between !== and != in PHP?

Possible Duplicate: php == vs === operator What's the difference between !== and != in PHP? ...

Using the conditional operator in conjunction with IsAjaxRequest to return ActionResult

Since there is no implicit conversion between Mvc.JsonResult and Mvc.ViewResult I cannot just utilize a conditional operator but instead end up with a cast. Which leads me to my question is the performance hit I will take for boxing the JsonResult worth it or should I just do a normal if...else block? The code below appears inside a no...

Conditional operator issue

I'm having some trouble with using the conditional operator to get a reference to an object. I have the a setup similar to this: class D { virtual void bla() = 0; }; class D1 : public D { void bla() {}; }; class D2 : public D { void bla() {}; }; class C { public: C() { this->d1 = new D1(); this->d2...

Using conditional operator in lambda expression in ForEach() on a generic List?

Is it not allowed to have a conditional operator in a lambda expression in ForEach? List<string> items = new List<string>{"Item 1", "Item 2", "Item I Care About"}; string whatICareAbout = ""; // doesn't compile :( items.ForEach(item => item.Contains("I Care About") ? whatICareAbout += item + "," : whatICareAbout += ""); Compilati...

Can every if-else construct be replaced by an equivalent conditional expression?

(I don't have a serious need for this answer, I am just inquisitive.) Can every if-else construct be replaced by an equivalent conditional expression using the conditional operator ?:? ...

Linq-Sql IQueryable<T> and chaining OR operations

I'm trying to simulate: WHERE x.IsActive = true OR x.Id = 5 The following causes 'AND' to be used... how do I simulate an 'OR' condition with IQueryable (qry) and my nullable int, given that other filtering might be involved as with the IsActive filter here? if (onlyActiveItems) //bool { qry = q...

Combine an 'in-line IF' (C#) with response.write

in a conventional C# code block: "myInt = (<condition> ? <true value> : <false value>)" but what about use inside an .aspx where I want to response.write conditionally: <% ( Discount > 0 ? Response.Write( "$" + Html.Encode(discountDto.Discount.FlatOff.ToString("#,###."): "")%> mny thx ...

ruby - if string is not contained within an array

I only want to output one anchor here. If the current_page is in the array I get two (.html and -nf.html). If it is not in the array I get as many anchors as there are items in the array. I am using StaticMatic. - if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0 // loop through the ...

Php ternary statement

Hi i was recently looking over a shopping cart paginator class, trying to understand their code so i could build my own paginator when i came across the following line of code. It resembles a ternary statement but is written in a way that i have never seen before. I would google it but i wouldn't know what to google. Could someone please...

Are multiple conditional operators in this situation a good idea?

I just saw this block of code on the Wikipedia article on conditional operators: Vehicle new_vehicle = arg == 'B' ? bus : arg == 'A' ? airplane : arg == 'T' ? train : arg == 'C' ? car : arg == 'H' ? horse : feet;...

PHP nested conditional operator bug?

return true ? 'a' : false ? 'b' : 'c'; This should return 'a', but it doesn't. It returns 'b' instead. Is there a bug in PHP's order of handling the different parts of the conditional operators? I got the idea from ht...

if statement on one line if poss...

I am printing an image using an ID which is generated. however i wanted to do a check to see if this image exists and if it doesnt print no-image.jpg instead... <img src="phpThumb/phpThumb.php?src=../public/images/'.$row["id"].'/th.jpg&w=162" alt="" width="162" /> It would be great if this could be kept on one line is possible. Any...

Check if int is between two numbers

Why can't do you this if you try to find out whether an int is between to numbers: if(10 < x < 20) Instead of it, you'll have to do if(10<x && x<20) which seems like a bit of overhead. ...