Mentions légales du service

Skip to content
Snippets Groups Projects
Closed Logical operators are also evaluated from the left to the right
  • View options
  • Logical operators are also evaluated from the left to the right

  • View options
  • Closed Issue created by ROUVREAU Vincent

    In 1-ProceduralProgramming/2-Conditions-and-loops.ipynb section Logical operators, it is explained that:

    • and takes precedence over or
    • Builtin operators && and || perform short-circuit evaluation: they do not evaluate the second operand if the result is known after evaluating the first

    but we do not explained that they are evaluated from the left to the right.

    Moreover, this example is a bit difficult:

    if (b++ == 3 && a < 0)
        ;
    
    std::cout << "b was incremented: " << b << 
        " (as first operation is true second one is evaluated)." << std::endl;

    FMHO, it would be easier to understand if it was the contrary than the example that is above:

    if (a > 0 && b++ == 3)
        ;
    
    std::cout << "b was incremented: " << b << 
        " (as first operation is true second one is evaluated)." << std::endl;

    Linked items ... 0

  • Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first
    Loading Loading Loading Loading Loading Loading Loading Loading Loading Loading