0

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!

Reginald
  • 798
  • 1
  • 6
  • 16

2 Answers2

0

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

Vihar
  • 3,626
  • 2
  • 24
  • 47
0

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.
}
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105