Print Page | Close Window

Ending While Loop

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5959
Printed Date: 31 March 2026 at 3:01am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Ending While Loop
Posted By: pmormr
Subject: Ending While Loop
Date Posted: 24 September 2003 at 4:44pm

I'm building a small search engine.. I wish to have a part 1 and a part 2 alternate between each other, my only problem is that i need to make sure that i'm not at recordset.EOF within mid loop. Sample Code:

<%
   While NOT rs.eof
%>
PT1
<%
   If NOT rs.eof then
   rs.movenext
Else
   (end loop)
end if
%>
PT2
<% Wend %>
  



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/



Replies:
Posted By: Gullanian
Date Posted: 24 September 2003 at 6:04pm

Ok, well why dont you use a switch variable:

Dim blnAtFirstStage
blnAtFirstStage = False

Do until rsCommon.eof
  If blnAtFirstStage = False then
    blnAtFirstStage = True
    'Do your stage one stuff
  Else
    blnAtFirstStage = False
    'Do your stage two stuff
  End if
rsCommon.movenext
Loop
rsCommon.close



Posted By: MorningZ
Date Posted: 24 September 2003 at 8:52pm

<%
   While NOT rs.eof
%>
PT1
<%
   If NOT rs.eof then
   rs.movenext
Else
   (end loop)
end if
%>
PT2
<% Wend %>

besides the fact that you totally needlessly say "If NOT rs.EOF" while inside the loop that flat out says already "i am not at the end of the recordset".. making asking "am i at the end" a waste of CPU cycles :-)



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 24 September 2003 at 8:55pm

While..Wend is kinda old school and more code than is needed...

Guillian suggested a good way, and then a new option opens up for you, "Exit Do" if you need to must out early.....

Here's more on the "Exit" statement of VBScript:
http://www.netzone.ch/caspdoc/html/vbscript_exit_statement.htm - http://www.netzone.ch/caspdoc/html/vbscript_exit_statement.h tm



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: pmormr
Date Posted: 25 September 2003 at 2:43pm
Morningz i don't think you entirely understand what i'm trying to do. I want to create a listing of all the records alternating the color of the row... I'm just having trouble figuring out how i'm going to do it.

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: pmormr
Date Posted: 25 September 2003 at 2:59pm
gullinan's switch variable thingy worked... thanks for your help

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net