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.
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?
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
}
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.
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.
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.