title: Possible to leave recursion prematurely?
body: <p>My current recursive function works to a degree, but then ruins itself when it goes back down the stack.</p>
  
  <pre><code>void Graph::findPath( Room * curRoom )
  {
  if( curRoom -&gt; myNumber == 0 )
  {
      cout &lt;&lt; "Outside.\n";
      //Escape the recursion!
  }
  else
  {
      curRoom -&gt; visited = true;
  
      if( curRoom -&gt; North -&gt; visited == false )
      {   
  
          escapePath[ _index ] = "North";
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          ++_index;
  
          findPath( curRoom -&gt; North );
  
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          escapePath[ _index ] = "";
          --_index;
      }
  
      if( curRoom -&gt; East -&gt; visited == false )
      {   
          escapePath[ _index ] = "East";
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          ++_index;
  
          findPath( curRoom -&gt; East );
  
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          escapePath[ _index ] = "";
          --_index;
      }
  
      if( curRoom -&gt; South -&gt; visited == false )
      {   
          escapePath[ _index ] = "South";
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          ++_index;
  
          findPath( curRoom -&gt; South );
  
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          escapePath[ _index ] = "";
          --_index;
      }
  
      if( curRoom -&gt; West -&gt; visited == false )
      {   
          escapePath[ _index ] = "West";
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          ++_index;
  
          findPath( curRoom -&gt; West );
  
          cout &lt;&lt; "_index: " &lt;&lt; _index &lt;&lt; "\n";
          escapePath[ _index ] = "";
          --_index;
      }
  }
  }
  </code></pre>
  
  <p>To save you some reading, the idea is that the base case is finding 0. Otherwise it tries four different cardinal directions, which is a different numbered room. Every time it makes a move, it adds the move it made to an external array, and every time it comes back up it removes that step from the stack.</p>
  
  <p>My issue is that it has the correct path stored when it finds the 0, but removes it on the way back up.</p>
  
  <p>Is there a way to escape it, such as a break.</p>
  
  <p>No gotos or exceptions</p>