user7019: (This might be more of a common C question)
I want to test several conditions in an IF-sentence
if(variable) {            // fastest check
  if(register) {          // a bit slower
    if(read_peripheral) { // very slow check
      // [do something]
    }
  }
}

It seems obvious that I want to start with the fastest check, and move on to the slower ones afterwards, potentially avoiding to check them if the above was false. 
Now since I need to check quite a few conditions, I'd like to know if the following is the same, or if all conditions will be evaluated prior to making a decision?
if(variable && register && read_peripheral) {
  // [do something]
}


user42: Putting them all in a single condition like that is absolutely fine. C/C++ uses "short circuit evaluation" which means it will stop as soon as it's determined the outcome. If everything is combined using logical AND operators (&&) then that means it will stop as soon as one of them evaluates to false.
For example:
 if (blah() && foo()) { ... }

If blah() returns false, it will never call foo() at all because it already knows the overall outcome is false.
The reverse happens with the logical OR operator (||):
 if (blah() || foo()) { ... }

If blah() returns true in this case, it won't call foo(). That's because it already knows the overall outcome is true.

7019: <p>(This might be more of a common C question)</p>

<p>I want to test several conditions in an IF-sentence</p>

<pre><code>if(variable) {            // fastest check
  if(register) {          // a bit slower
    if(read_peripheral) { // very slow check
      // [do something]
    }
  }
}
</code></pre>

<p>It seems obvious that I want to start with the fastest check, and move on to the slower ones afterwards, potentially avoiding to check them if the above was false. </p>

<p>Now since I need to check quite a few conditions, I'd like to know if the following is the same, or if all conditions will be evaluated prior to making a decision?</p>

<pre><code>if(variable &amp;&amp; register &amp;&amp; read_peripheral) {
  // [do something]
}
</code></pre>
 42: <p>Putting them all in a single condition like that is absolutely fine. C/C++ uses "short circuit evaluation" which means it will stop as soon as it's determined the outcome. If everything is combined using logical AND operators (&amp;&amp;) then that means it will stop as soon as one of them evaluates to false.</p>

<p>For example:</p>

<pre><code> if (blah() &amp;&amp; foo()) { ... }
</code></pre>

<p>If <code>blah()</code> returns false, it will never call <code>foo()</code> at all because it already knows the overall outcome is false.</p>

<p>The reverse happens with the logical OR operator (||):</p>

<pre><code> if (blah() || foo()) { ... }
</code></pre>

<p>If <code>blah()</code> returns <em>true</em> in this case, it won't call <code>foo()</code>. That's because it already knows the overall outcome is true.</p>
