为什么这是一个“如此接近却如此遥远”的事? 如果声明?
我正在编写一个 If 语句,我想满足两个条件来忽略循环。 起初这似乎很容易,但现在……我不知道。 这是我的困境...
if((radButton1.checked == false)&&(radButton2.checked == false))
{
txtTitle.Text = "go to work";
}
困境是如果 radButton1 为 false 并且 radButton2 为 true,则不会执行“去工作”。 难道不应该要求两个条件都为假才能跳过该语句吗?
I am working on an If statement and I want to satisfy two conditions to ignore the loop. This 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 dilemma is "go to work" is not executed if radButton1 is false and radButton2 is true. Shouldn't it require both conditions to be false in order to skip the statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
不,它要求它们都为假才能执行该语句。
No, it requires them to both be false to execute the statement.
不,它需要两个条件都为假才能执行该语句。 再读一遍:
英文:“如果 radButton1.checked 为 false AND radButton2.checked 为 false,则设置
将 txtTitle.Text 改为“去工作””。
如果您想在两个条件都为假时跳过该语句,则否定您的逻辑,如下所示:
翻译成英语将显示:“如果 radButton1.checked 为 true OR radButton2。 check is true, then set the text to 'Go to work'”。这意味着如果任何条件为真,它将执行该语句,或者,如果两者都为假,则跳过它。
Nope, it requires both conditions to be false to execute the statement. Read again:
In English: "If radButton1.checked is false AND radButton2.checked is false, then set
the txtTitle.Text to 'Go to work'".
If you want to skip the statement when both conditions are false then negate your logic, like this:
This, translated to 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, to skip it.
假设我有两个名为
A
和B
的变量,如果 A 和 B 具有这些值
,则这些操作返回
请注意,第二个表中的底部 3 是逻辑相反的(即它们同表中前 3 名中的“尚未申请”。
Say I have two variables named
A
andB
If A and B have these values
then these operations return
Note that the bottom 3 in the second table are the logical opposites (i.e. they've had NOT applied) of the top 3 in the same table.
与真(或假)进行比较是完全没有必要的:
成为
或等于
comparing to true (or false) is entirely unnecessary:
becomes
or equally
在您的示例中,如果两个按钮都为 false,它只会执行 txtTitle.Text ="go to work" 代码。 因此,一为真,一为假,它将跳过该语句。
In your example it will ONLY execute the
txtTitle.Text ="go to work"
code if BOTH buttons are false. So one being true and one being false it will skip the statement.不。需要其中一个语句为假才能跳过。 看看你的 if:
所以如果条件 1 或条件 2 不成立,那么它不会执行。
No. It requires one of those statements to be false to skip. Look at your if:
So if condition1 OR condition2 is not true then it won't execute.
我让它工作了。 我发现它们都需要为 false 才能执行该语句,对于该语句,满足这两个条件的方法是使用
I got it to work. I see that they both need to be false to execute the statement, for that statement, the way to satisfy both conditions is by using