"unassigned local variable 'mylist' error" given loop containing initiatization will be entered once? And how to make the code recursive?
<pre><code>List&lt;string&gt; Getlist()
{
    List&lt;string&gt; mylist;
    for (bool successFlag = false; !successFlag; )  //It will definitely enter the loop once.
    {
        successFlag = true;
        mylist = new List&lt;string&gt;();
        for (int i = 0; i &lt; n; i++)
        {
            var CDF = GetCDF(); // IEnumerable, each call of GetCDF() gives different result
            if (!CDF.Any())
            {
                fail++;
                successFlag = false;
                break;
            }
            string item = GetNext(CDF);
            mylist.Add(item);
        }
    }
    return mylist; // Here IDE poses an error
}
</code></pre>

<p>I guess there is a way to recursively use <code>Getlist()</code> instead of do a <code>for</code> loop and <code>flag</code> retry, maybe some kind of immutable method?</p>

<p>i dont wanna initiate the list outside the loop because i would like to discard the list when <code>successFlag</code> is <code>false</code>;</p>

<p>Discard simply means when <code>successFlag = false</code>, then <code>mylist.removeall</code>. And then start everything over again as fresh, so I am asking for an approach to recursively call <code>GetList()</code> instead of clear the states in the method</p>

<p><strong>Update</strong></p>

<p><code>do while</code> works!</p>
