Came across this line in a program I'm cleaning up:
isFound = !isFound ? isFoundOnPost : isFound;
I tried to Google this, yieleded no results. I know this is not the best question but could someone explain what this is doing? Thanks!
Came across this line in a program I'm cleaning up:
isFound = !isFound ? isFoundOnPost : isFound;
I tried to Google this, yieleded no results. I know this is not the best question but could someone explain what this is doing? Thanks!
This is use of ternary operator its syntax is
variable=(condition)?IfConditiontrueThisExecutes:IfConditionFalseThisExecutes;
it is somewhat similar to if-else ,
whenver the condition before ?
evaluates to true the statement after ?
gets executed otherwise statement after :
get executed and variable on LHS is assigned that value based on which statement executed
It's called as Ternary operator. It is same as
if(!isFound) {
isFound = isFoundOnPost;
} else {
isFound = isFound; //No need, Just to make clear for you.
}