Search code examples
pseudocode

Do && operators only evalutate the right-hand side if the previous condition was met?


If I wanted to check if a multidimensional list had a value multiple levels down, could I just do something like

if(list.contains("value") 
   && list.get("value").contains("value")
   && list.get("value").get("value").contains("value")
   && ...)

or will it still check the other statements after the previous condition was false, resulting in a null pointer error?

Also is it language specific or a universal standard, because I've figured out that python and java'll ignore a condition if the previous was false, but would this still work on low-level languages?


Solution

  • This is called "short-circuit evaluation" and is language dependent. You can see the wiki article on this which describes the feature by language:

    https://en.wikipedia.org/wiki/Short-circuit_evaluation