Why is this statement "so close, but still"?
I am working on an If statement and I want to fulfill two conditions to ignore the loop. It seemed easy at first, but now ... I don't know. this is my dilemma ...
if((radButton1.checked == false)&&(radButton2.checked == false))
{
txtTitle.Text = "go to work";
}
The go-to-work dilemma fails if radButton1 is false and radButton2 is true. Doesn't that require both conditions to be false in order to skip the statement?
No, it requires both conditions to be false in order to execute the instruction. Read again:
if ((radButton1.checked == false) && (radButton2.checked == false)) {
txtTitle.Text = "Go to work";
}
In English: "If radButton1.checked is false and radButton2.checked is false, then set txtTitle.Text to Go to Work."
If you want to skip a statement when both conditions are false, then negate your logic, e.g .:
if ((radButton1.checked == true) || (radButton2.checked == true)) {
txtTitle.Text = "Go to work";
}
This, translated into English, would read: "If radButton1.checked is true OR radButton2.checked is true, then set the text to" Go to work "". This means that if any condition is true, it will execute the statement or, if both are false, skip it.
source to share
Let's say I have two variables named A
andB
If A and B have these meanings
A true true false false
B true false true false
then these operations return
AND true false false false
OR true true true false
XOR false true true false
NAND false true true true
NOR false false false true
XNOR true false false true
Note that the bottom 3 in the second table is the logical opposites (i.e. they did NOT apply) from the top 3 in the same table.
source to share