Questions tagged [shorthand-if]

47 questions
2
votes
3 answers

PHP Multiple actions in true clause in shorthand IF

Pretty sure there's a simple answer to this but difficult to search on because of the vague terms used. I'm using shorthand if statements and want to do more than one action when it returns true, what does the syntax look like? For example,…
Joe
  • 461
  • 1
  • 6
  • 15
2
votes
4 answers

nested shorthand if

I have a little trouble with a shorthanded if statement I can't figure out ($product == "vindo") ? $this->getNextVindoInList($id) : $this->getNextGandrupInList($id), This works fine but I want to have another check in that statement. Like…
Morten Hagh
  • 1,853
  • 5
  • 31
  • 57
1
vote
4 answers

Shorthand if not running or evaluating

I'm basically checking a users download limit in my database, and if their limit is < 1 I want to disable a input on my page. /> When the page is run,…
Josh
  • 1,301
  • 5
  • 22
  • 33
1
vote
3 answers

PHP If Shorthand Best Practce

Just a weird PHP question about best practice. Assuming the following function: function get_option($val) { return false; } I want to assign to a $locale variable, the value returned from this function and, if false, set to a default en_GB one. I…
andreasonny83
  • 1,108
  • 9
  • 19
1
vote
0 answers

jshint complains about shorthand AND operator with boolean

I've got a javascript function that needs to be executed based on a boolean value. I really like to use the && operator for this (which only executes the second part if the first results in true). someBoolean && executeFunction(); However, when…
Justus Romijn
  • 13,863
  • 4
  • 47
  • 59
1
vote
3 answers

Shorthand if ? return : null

I want to achieve this: if (full) { return } else{ // nuthin } But shorter, something like: full ? return : null; But that doesn't work.. I could do: if (full) { return } But I like the ternary more I expected something…
TrySpace
  • 1,875
  • 8
  • 26
  • 57
1
vote
4 answers

Why is an empty value in a shorthand if-then-else returning `true`?

This is not exactly a "problem", but more a "why" question. Based on the following example: echo 'test' . ( true ? : 'some-test' ); Why is the result of this: test1 instead of what one might expect: test. Or in other words: Why is an empty return…
Damien Overeem
  • 4,399
  • 4
  • 31
  • 53
1
vote
2 answers

MVC4 Razor shorthand if

@{(int)Session["current"] == 1 ? Html.ActionLink("Home", "Index", "Home", new { @class = "selected" }) : Html.ActionLink("Home", "Index", "Home");} When I use this code I get an error: CS0201: Only assignment, call, increment, decrement,…
1
vote
1 answer

Shorthand if/else statements : foo?foo:bar vs foo || bar

I wonder how this two are different ? var hello = foo?foo:bar; vs var hello = foo || bar; Can you explain this ? and some case example ? or both are same ? PS : foo/bar should be all like string / int / obj / boolean...
l2aelba
  • 18,585
  • 20
  • 90
  • 131
1
vote
3 answers

Trouble changing attribute with shorthand if

I was just wondering if I could get some pointers please. I am using a shorthand if to change text based on whether a div is toggled. This is what I have for the text changer: $(this).text($(this).text() == 'Email Me' ? 'Close Form' : 'Email…
Chris
  • 311
  • 1
  • 4
  • 15
1
vote
3 answers

Short hand if statement

Is there a shorter version of the following: Using ASP.NET MVC, this is in the HTML page <%= IsTrue ? Html.Image("~/images/myimage.gif") : "" %> I know I'm only really writing 3 extra characters, just wondering if there is something better.
Omar
  • 37,391
  • 42
  • 132
  • 207
1
vote
1 answer

Can't see why this simple if statement returns null?

Or if the if statement doesn't return null - why this particular property can't be assigned to. Example: String stringParam = "some string"; MyClass myclass = new MyClass(); myclass.MyProperty = MyMethod(out stringParam ) ? stringParam :…
user1017882
1
vote
2 answers

javascript shorthand syntax

I was wondering how this could be written in shorthand that the statement would execute This one isn't working, but I see this kind of syntax lots of times in plugins - variables mixed with statements etc.. Can someone give an explanation regarding…
Richard
  • 4,348
  • 11
  • 57
  • 86
0
votes
1 answer

CUDA's nvcc Does Not Properly Compile Ternary Operators/Conditional Shorthand?

EDIT Here's a small program you compile to see these kind of errors for yourself... //for printf #include #include __inline __host__ void gpuAssert(cudaError_t code, char *file, int line, bool abort=true) { …
Jason R. Mick
  • 4,797
  • 4
  • 36
  • 61
0
votes
1 answer

javascript shorthand if the else callback

the long hand if in javascript would look: function somefunction(param){ if(typeof(param) != 'undefined'){ var somevar = param; } else { alert('ERROR: missing parameter in somefunction. Check your form'); …
IberoMedia
  • 2,126
  • 7
  • 32
  • 57