title: Not all code paths return a value in case of a recursive algorithm
body: <p>I've just designed a recursive algorithm and implemented in C# encountering <code>not all code paths return a value</code> error. Here is the code:</p>
  
  <pre><code>public List&lt;List&lt;Event&gt;&gt; CollectPaths(IEnumerable&lt;string[]&gt; transitions, State q_r, State q_s, List&lt;State&gt; Q_T, ref List&lt;Event&gt; tempPath)
          {
              if (!Q_T.Any())
              {
                  pathCollection.Add(tempPath);
                  return pathCollection;
              }
  
              else
              {
                  List&lt;State&gt; Q_O = new List&lt;State&gt;();
                  Q_O = Get_Q_O(q_r, transitions);
  
                  State qq = new State("");
  
                  foreach (State q in Q_O)
                  {
                      List&lt;Event&gt; S_O = new List&lt;Event&gt;();
                      List&lt;Event&gt; S_OO = new List&lt;Event&gt;();
                      S_O = Get_S_O(q_r, q, transitions);
                      S_OO = Get_S_OO(q_r, q, S_O, transitions);
  
                      if (q.ID == q_s.ID)
                      {
                          tempPath.AddRange(S_O);
                          pathCollection.Add(tempPath);
                          Q_T.Remove(q);
                          if (!Q_T.Any())
                              return pathCollection;
                          else
                              continue; /////////////Note 1
                      }
  
                      else 
                      {
                          foreach(Event sigma in S_O)
                          {
                              if (AFC_1(S_OO) ||
                               AFC_2(S_OO) ||
                               (AFC_3_1(S_OO, S_O) &amp;&amp; AFC_3_2(GetC_S_OO(S_OO), GetU_S_OO(S_OO)))
                              )
                              {
                                  tempPath.AddRange(S_O);
                                  Q_T.Remove(q);
                                  CollectPaths(transitions, q, q_s, Q_T, ref tempPath);
                              }
  
                              else
                              {
                                  Q_T.Remove(q);
                                  if (!Q_T.Any())
                                      return pathCollection;
                                  else
                                      continue; /////////////Note 2
                              }
                          }
                      }
                  }
              }
          }
  </code></pre>
  
  <p>There are many conditional branches, and I've done my best to make algorithm return the <code>pathCollection</code>, finally.</p>
  
  <p>Some Remarks:</p>
  
  <p><code>Note 1</code> and <code>Note 2</code>: the <code>continue</code> continues the <code>foreach</code> for the other values of <code>q</code>. Then, either it will get rid of the <code>if</code> and execute the <code>else</code>; or <code>Q_T</code> (a global variable which can be changed by all instantiations of the function) will become empty and <code>pathCollection</code> returns.</p>
  
  <p>But I can't figure out what's wrong with this code!</p>
  
  <p>Could you please give me some advice about it?  </p>