title: Abort a procedure with flag, return, exception, goto or break
body: <p>I've got a code which parses a file and breaks up if invalid conditions are met.
  The code is in C++ and goes like that:</p>
  
  <pre><code>bool ok = true;
  if (task1() == false)
      ok = false;
  if (ok &amp;&amp; (task2() == false))
      ok = false;
  if (ok &amp;&amp; (task3() == false))
      ok = false;
  cleanup();
  return ok;
  </code></pre>
  
  <p>Now I'm looking into cleaner alternatives to get the same result.
  As far as I see there are:</p>
  
  <ul>
  <li>using a flag and many conditions as in the code above
  
  <ul>
  <li>There are many redundant tests for the same information.
  The effect on the runtime will be negligible and probably
  entirely removed by the compiler but it still makes the code
  more complicated.</li>
  </ul></li>
  <li>you could wrap the tasks in a method and return from it
  
  <ul>
  <li>This looks much cleaner but you spread your code in multiple
  functions. Depending on your context there might be a long
  list of parameters. Further more many it is also not the
  best to spread returns all over the method.</li>
  </ul></li>
  <li>you could use exceptions
  
  <ul>
  <li>This will give some quite descriptive code but it is also
  heavy as you just want to skip some calls. Further more it
  might not be exactly an exceptional case.</li>
  </ul></li>
  <li>you could <code>break</code> from a <code>do while(0)</code> or another loop
  or switch statement.
  
  <ul>
  <li>Well, it is not really meant for such a task. Other than
  that you get a lightweight and compact implementation with
  and descriptive keyword.</li>
  </ul></li>
  <li>using a <code>goto</code> statement
  
  <ul>
  <li>That seems to combine most advantages. Still, I am unsure.
  Everywhere people are stating, that breaking multiple loops
  is the only remaining sensible use for this keyword.</li>
  </ul></li>
  </ul>
  
  <p>I didn't find a discussion about such a code. Which implementations are generally suggested? Is this case mentioned in any C++ coding guidelines? Are there other practical options?</p>
  
  <p><em>Edit:</em> My goal does not seem to be clear. I'm looking for the best way how to break from a procedure and not for a way to call three methods. The described problem is more of an example. I'm interested in arguments for and against different syntaxes to do this.</p>
  
  <p>In the code of object each method is a placeholder for a couple of code lines which are similar but differ from each other. There are maybe 50 code blocks. An old code block was looking like the following (I know that there are more things to optimize than just the objective of this question):</p>
  
  <pre><code>if (ok)
  {
      keyString = "speed";
      tmpVal = configuration-&gt;getValue(section, keyString, -1);
      if (tmpVal != -1)
      {
          m_speed = tmpVal;
          if (m_speed &lt; m_minSpeed)
              m_minSpeed = m_speed;
          m_needSpeed = true; 
      }
      else if (m_needSpeed)
      {
          ok = false;
          keyErr = keyString;
      }
  }
  </code></pre>