While loop difficulty
<p>I am trying to compare a list AAA that contain Date with a range of dates.  I want to see if any of the range of date is present in the list or not.  If the date is present I copy the list items to another list BBB else I add empty values to the list BBB.</p>

<p>The problem I am having is that with my actual code, is I don`t know how not pass through the false statement of the while loop, till it reaches the end of the comparison.</p>

<p>With the code below, it is passing both the true and false in the while loop, which is falsifying the required result. The result I am obtaining is for every time that is present, I am having the same time as false.  In short, lets say the list contains the date 6/5/2010, and the range of date is 4/5/2010 to 7/5/2010.  so I will have an item created in the true part and AN ITEM CREATED INTHE FALSE PART, which is wrong.  The date present can either be in true or false part.  Not both, such that I have two items bing created!</p>

<p>How can I achieve the right result? Any other method or suggetsion please.</p>

<p>My code is as follows:</p>

<pre><code>DateTime StartDate; 
DateTime EndDate;
Datetime tempDate = StartDate;
List&lt;DateTime&gt; dateToEvaluate;

bool TimeIsPresent = false;
foreach (var tempItem in TaskList)
{
    while (EndDate.AddDays(1) != tempDate)
    {
        if (tempItem.Date[0] == tempDate)
        {
            TimeIsPresent = True;
            break;
        }
        else
        {
            if (TimeIsPresent == False)
            {
                if (!(tempDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    dateToEvaluate = new List&lt;DateTime&gt;();
                    dateToEvaluate.Add(tempDate);
                    tempTask.Add(new GroupedTask { ID = null,
                                                   TaskID = null,
                                                   Date = dateToEvaluate });
                 }
             }
         }

         tempDate = tempDate.AddDays(1);
                  }

     if (TimeIsPresent == True)
     {
         tempTask.Add(new GroupedTask { ID = tempItem.ID,
                                        TaskID = tempItem.TaskID,
                                        Date = tempItem.Date });
         TimeIsPresent = false;
     }
 }
</code></pre>

<hr>

<p>let me give you an example. My range of date is as follows: Mon 8 Aug - Sunday 14 Aug. 
Now my tasklist is as follows: item1: Date 9Aug, item2: Date 11Aug. </p>

<p>So my tempTask must be as follows: 
item1: Date 8 Aug, taskID: null, ID: null, 
item2: Date 9 Aug, taskID: 678, ID: 7,
item3: Date 10Aug, taskID: null, ID: null, 
item4: Date11 Aug, taskID:890, ID: 34, 
item5: Date 12 Aug, taskID: null, ID: null, 
item6: Date 13 Aug, taskID: null, ID: null </p>

<hr>

<p>Second example:</p>

<p>My range of date is as follows: Mon 8 Aug - Sunday 14 Aug. 
Now my tasklist is as follows: item1: Date 9Aug, item2: Date 11Aug, item3:  Date 14Aug </p>

<p>So my tempTask must be as follows: 
item1: Date 8 Aug, taskID: null, ID: null, 
item2: Date 9 Aug, taskID: 678, ID: 7,
item3: Date 10Aug, taskID: null, ID: null, 
item4: Date11 Aug, taskID:890, ID: 34, 
item5: Date 12 Aug, taskID: null, ID: null, 
item6: Date 13 Aug, taskID: null, ID: null,
item4: Date14 Aug, taskID:894, ID: 74,</p>
