Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Do while循环条件语句否定等价_C++_Logic_Conditional Statements_Negation - Fatal编程技术网

C++ Do while循环条件语句否定等价

C++ Do while循环条件语句否定等价,c++,logic,conditional-statements,negation,C++,Logic,Conditional Statements,Negation,社区和编程新手。我很好奇为什么这两个逻辑语句在我的程序中是等价的。目前,我似乎无法理解这个特定的逻辑,我想理解为什么它是这样工作的 最初,我写了以下内容: char c; do { cin >> c; cout << "You entered: " << c << "\n"; } while (c != 'Y' || c != 'y' || c != 'N' || c || 'n');

社区和编程新手。我很好奇为什么这两个逻辑语句在我的程序中是等价的。目前,我似乎无法理解这个特定的逻辑,我想理解为什么它是这样工作的

最初,我写了以下内容:

    char c;
    do {
        cin >> c;
        cout << "You entered: " << c << "\n";
    } while (c != 'Y' || c != 'y' || c != 'N' || c || 'n');
    return 0;
}

do while循环中的这些逻辑表达式

while (!(c == 'Y' || c == 'y' || c == 'N' || c || 'n')); // Will run until c is the following
while (c == 'Y' && c == 'y' && c == 'N' && c == 'n'); // Will also run but without being negated.
它们并不等同

表情

while (!(c == 'Y' || c == 'y' || c == 'N' || c || 'n'));
相当于

while ( c != 'Y' && c != 'y' && c != 'N' && !c && !'n' );
!( a == b ) && !( c == d )
如果你有一个表达式,比如

a == b || c == d
然后是否定

!( a == b || c == d )
相当于

while ( c != 'Y' && c != 'y' && c != 'N' && !c && !'n' );
!( a == b ) && !( c == d )
终于

a != b && c != d
注意这个边做边循环

char c;
do {
    cin >> c;
    cout << "You entered: " << c << "\n";
} while (c != 'Y' || c != 'y' || c != 'N' || c || 'n');
charc;
做{
cin>>c;

cout De Morgan定理可能是一个有用的搜索词,速度惊人。我正在重新编辑发布的问题,突然意识到我无意中为&&条件语句写了“==”,并不得不更正它。我知道它们被认为是等价的,但为什么?