Reputation: 7375
below is simple ternary operator.
hc.colspan= ( hc.colspan == 1 && hierarchycount == 0) ? hc.colspan : hc.colspan +1
I need to make this more simple instead of assigning the same value to hc.colspan when the condition is true.
How can I do this without assigning same value to hc.colspan when the condition is true.
like consider another example
a = a!=0 ? a : b
Above we are assigning same a value to "a" again when the condition comes to true. But I don't want to assign it again. How can I do this in a different manner?
Upvotes: 0
Views: 90
Reputation: 44438
You'll have to remove the ternary operator and go with a normal if
statement:
if(!(hc.colspan == 1 && hierarchycount == 0)){
hc.colspan += 1;
}
or, inversed per MarkO's suggestion:
if(hc.colspan != 1 || hierarchycount != 0){
hc.colspan += 1;
}
Upvotes: 2
Reputation: 17560
For your first example you could do this:
hc.colspan += (hc.colspan == 1 && hierarchycount == 0) ? 0 : 1;
But generally, if you only want to change the value in one case, just use an if
clause.
Upvotes: 0
Reputation: 4695
Why not simply
if(!(hc.colspan == 1 && hierarchycount == 0))
hc.colspan++;
Upvotes: 1