1

My question is if(bool || bool) is the syntax. If first bool is true does the compiler check for the second bool condition? And also is this same for all programming languages out there ?

#include <iostream>

using namespace std;

int main() {
    // Write C++ code here
   
    int i = 2,j = 0;
    
    while(i-- || j++){
        cout << j << " " << i << endl;
    }
        
    return 0;
}

By the way answer for above code is ::

0 1

0 0

  • 2
    Does this answer your question? [Is short-circuiting logical operators mandated? And evaluation order?](https://stackoverflow.com/questions/628526/is-short-circuiting-logical-operators-mandated-and-evaluation-order) – Passerby Dec 09 '21 at 07:05
  • No, it is not the same for all languages. For example, Visual Basic doesn't have `||`. It does have `Or`, which evaluates both arguments, and `OrElse`, which behaves like C `||`. – Amadan Dec 09 '21 at 07:09
  • No, in c/c++ compiler will not check cond2, if cond1 is true in if ( cond1 || cond2). also if we use && (AND logical operator ) and first condition is false the next condition will not be checked. – Gautam Jangid Dec 09 '21 at 07:20
  • *"is this same for all programming languages out there"* -- I would be willing to say that all programming languages enable humans to tell computers what to do. Beyond stuff on that level... not sure if there is anything I would be confident saying is the same for all programming languages out there. – JaMiT Dec 09 '21 at 07:26

0 Answers0