title: How to avoid this nested if statement?
body: <p>I want to check if <strong>one</strong> file exists in two different paths. If the first one doesn't, check the second.</p>
  <pre><code>filepath1 = &quot;/path1/file.txt&quot;
  filepath2 = &quot;/path2/file.txt&quot;
  file_descriptor = open(filepath1)
  
  if ( !file_descriptor.open() )
  {
      print(&quot;file 1 did not work&quot;);
     
      //try file 2
      file_descriptor = open(filepath2);
      if( !file_descriptor.open() )
      {
          print(&quot;could not open file 2. exiting.&quot;);
          return false;
      }
  }
  
  //we get here and file_descriptor should point to a valid file
  read_file(file_descriptor);
  return true;
  </code></pre>
  <p>How can I avoid the nested <code>if</code> statement? Preferably, I'd like to not nest the <code>if</code> statements for readability.
  The problem here is that if the first one does work, I don't want it to check the second <code>if</code> statement.</p>
  <p>I thought about using:</p>
  <ul>
  <li><code>goto</code> (I want to avoid this)</li>
  <li>boolean to check if one works (but now I'm introducing extra variables)</li>
  </ul>