what is if(!boolean) ?

Hi to all.... I wasa reading and studying this code and I got an idea of all the fuctions and what they do... Except for if(! Found)

int randNumber;
#define Count 10
int list[Count];
byte i = 0;
boolean found = false;

void setup()
{
  Serial.begin(115200);
  for (byte K = 0; K < 5; K++)
  {
    for (int j = 0; j < Count; j++)
      list[j] = -1;

    randomSeed(K + 1);
    delay(50);
    i = 0;
    found = false;
    while (i < Count)
    {
      randNumber = random(0, Count);
      for (byte L = 0; L < i; L++)
      {
        found = false;
        if (list[L] == randNumber)
        {
          found = true;
          break;
        }
      }
      if (!found)
      {
        list[i] = randNumber;
        Serial.print(list[i]);
        Serial.print(",");
        i++;
      }
    }
    Serial.println();
  }
}

void loop() {
}

As for I read.... If, not, boolean? But this means the logical comparison will be always true?

I ask because if( found ==false)
Or if (found != false ) I can understood that.

But no clue for the other... :astonished:

Thanks for the help...

Please excuse my ignorance.

-Alex.

if (!found) ...

It means "not found". I.e. the thing wasn't found.

If your wife says "is it raining?" and you say "it is not raining", that is clear, isn't it?

You don't have to say "it is false that it is raining".

Simple as that?

My question merge because the bollean value found=false at the beginig of the code....

But on that particular point I Dont see the logic comparison, as you make clear... Just say.... If not found....denaying either true or false.... This always be true..?
If not true
If not false..... But were is the logical comparison?
Both satatments above are ???? Correct?
If so.... Why dotn just. Type the code?

Sorry if it a dumb question, but I have never seen this before.
Thanks!

You don't have to make a comparison. if evaluates the conditional expression, and if the result of evaluating the expression is true, then it executes the if clause. The expression can be as simple as a single variable, or 10 lines of complex expressions with comparisons, ands, ors, nots, xors, etc.

Regards,
Ray L.

If not found....denaying either true or false.... This always be true..?

No, it isn't denying the type, it is denying the value.

"found" is a boolean type. It can be true or false. If it is false, it is not true, right?

It someone asks you if it is raining, you don't reply "there is no weather out here" (which wouldn't make sense). It is either true, or false, that it is raining.

RayLivingston:
You don't have to make a comparison. if evaluates the conditional expression, and if the result of evaluating the expression is true, then it executes the if clause. The expression can be as simple as a single variable, or 10 lines of complex expressions with comparisons, ands, ors, nots, xors, etc.

Regards,
Ray L.

Thanks Ray....still my doubt remains.
If (! BoolVar)
This as far I can tell it says something like;

If not (true||false) \is the same as?
If (! a)

Therefore the code will be executed.... But on this case .... This if is just for say "groupe" code ? Instead of a subfunction?

So the author of the code whant to separate this part as a block for clearest view?

Or I'm evaluating the code wrong?

Thanks !
-Alex

Thanks for the reply Nick.

Well I understood we are not denying the boolean.

I'm just trying to evaluate correctly the function.

Lets say boolean =true

If (! Boolean) as boolean can be true or false. And we are not comparing with any previus state.... This is always true?

If the next loop the variable changes to false..... The if statement remains true?
-Alex

I don't understand what you're trying to say here:

If (! BoolVar)
This as far I can tell it says something like;

If not (true||false) \is the same as?
If (! a)

It's very simple. The ! operator simply "flips" the boolean value of what follows it.

!true == false
!false == true

boolean x;

x = true
if (x)
{
    Code here WILL be executed
}

if (!x)
{
    Code here will NOT be executed
}

x = false;
if (x)
{
    Code here will NOT be executed
}

if (!x)
{
    Code here WILL be executed
}

int y = 5;
if (y == 5)
{
    Code here WILL be executed
}
if (!(y == 5))
{
    Code here will NOT be executed
}

if (y == 7)
{
    Code here will NOT be executed
}
if (!(y == 7))
{
    Code here WILL be executed
}

Regards,
Ray L.

It's very simple. The ! operator simply "flips" the boolean value of what follows it.

Thank you, I have the miss conception the ! Operator was -not-

Know makes perfect sense what the author of the code was implementing.

As the number only can or can't be on the array uses this comparisson to changue the behavior of the code.
Even the variable is... Found or not found.
Thanks! For the pattience and the replay.

-Alex.

I have the miss conception the ! Operator was -not-

The ! operator IS logical not, or negation, or inversion. What's' true becomes false, what's false becomes true. Exactly like XORing a single bit with 1. 0 becomes 1, and 1 becomes 0.

Regards,
Ray L.

Sorry for the late reply... yesterday was late and today was very busy on the job..

Now I understood.

If makes a logical comparison between the (), not necessarily between two variables or a variable and is previous state:

So;

x = true; 
if(x) // will be true ... 

x = false 
if (!x) //will also be true because we are evaluating something like 

 //if 
// Not- flips the previous state  
// previous state = false 
// state = true 

Therefore the logical comparison is true.

Thanks for this explanation, know I can come back to study and once complete digested, implement
some of the code on my own application.

Thank you @Nick Gammon, @RayLivingston

Kind regards.

-Alex

Correct, "if" does not take into account past events.