Looping - do until or not?

Results 1 to 3 of 3

Thread: Looping - do until or not?

  1. #1
    Join Date
    Dec 1969

    Default Looping - do until or not?

    I&#039;m using SELECT TOP 5 and looping using: Do Until rs.EOF<BR><BR>Is this efficient? Is it only selecting the top 5 and not running through the enitre database? Should I use NOT rs.EOF? I was thinking that SELECT TOP would mean that I wouldn&#039;t need to worry about it running the enitre database to grab the top fields.<BR><BR>Am I correct?<BR>

  2. #2
    Join Date
    Dec 1969

    Default Stick with a do-while

    Reason being, for the most part, for...next loops are when you know the quantity. While loops are used when you don&#039;t know when it&#039;ll end...<BR><BR>But, let&#039;s say tomorrow you change your query to select top 10. With the for loop, you have to change it in two places... not so with the do.

  3. #3
    Join Date
    Dec 1969

    Default I don't understand DGs reply

    DG: Where did he discuss a FOR loop???<BR><BR>Astralis: There is *ZERO DIFFERENCE* between doing<BR> Do Until RS.EOF<BR>and<BR> Do While Not RS.EOF<BR><BR>Use whichever you are comfortable with.<BR><BR>I don&#039;t understand your question about not needing "to worry about it running the entire database". It won&#039;t. It will run as many records as are in the recordset. Period. EOF has *NOTHING* to do with "the entire database".<BR><BR>As for doing<BR> For i = 1 To 5<BR><BR>That&#039;s not a good idea because:<BR> (1) As DG pointed out, what happens if you change your mind and do SELECT TOP 10 instead?<BR><BR> (2) Even if you do SELECT TOP 5, there is *NO GUARANTEE* that you will actually get 5 records. Maybe there are only 3 records that meet the WHERE clause of your query. Or, if you are using Access, when you do SELECT TOP 5 if there are 10 records that all "tie" (have equal values) for the top spot, then you will get all 10, not just 5.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts