Which LOOPING Statement is the best ?

Results 1 to 3 of 3

Thread: Which LOOPING Statement is the best ?

  1. #1
    Join Date
    Dec 1969

    Default Which LOOPING Statement is the best ?

    I would like to know that performance wise which looping statement would be better with reasons.<BR><BR>For..Next, Do While, Do Until, While.. Wend ?<BR><BR>Also would like to go thru some good articles on improving performance. (Please suggest articles other than the 25+ tips of Microsoft and all those in 4Guys)

  2. #2
    Join Date
    Dec 1969

    Default RE: It depends. . .

    I may get shot down, but here&#039;s when I use them.<BR><BR>For i = 0 to 5<BR>Next<BR>&#039; I usually use this one when I know how many times I want to loop some thing. Occasonally I will use a variable in the 5 spot.<BR><BR>For Each i_file in i_folder<BR>Next<BR>&#039; I would say that the majority of the time I use this one for counting or displaying files in a folder. I find it the fastest and easiest way to do so. If you do not want to use a DB then it&#039;s simple to display images. Not the only use though. Note you need to use the file counting with FSO.<BR><BR>Do While i &#060;&#062; i_2<BR>Wend<BR>&#039; I rarely use this. It keeps looping until the citeria is meet. I t is usefull at times.<BR><BR>Do Until &#039;I have not used this one yet. So I can&#039;t comment.<BR><BR>While Not R_recordset.EOF<BR><BR>R_recordset.MoveNext<BR>Wen d<BR>&#039; I personally use this one a lot with record sets. It&#039;s extemely useful. You could put the "&#060;option&#062;[name]&#060;/option&#062;" inside to creat a drop down or put and if...then to count how items meet the statement. I would try and use stored procedure before using it for straight counting.<BR><BR>Now I will have to look into the Do Until statment.<BR><BR>Hope that helps.<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Doesn't matter...

    You use the one that fits the needs of your program best. The performance differences between them are *SO* minor that you&#039;d have a heluva time measuring them.<BR><BR>And even if you did, you might just be fooling yourself!<BR><BR>Oh...and it matters not whether you use<BR><BR>WHILE something .... WEND<BR>or<BR>DO WHILE something .... LOOP<BR>or<BR>DO UNTIL something ... LOOP<BR><BR>All of them end up generating the same "byte code" in the end. So you use DO UNTIL in order to avoid having to use NOT with DO WHILE:<BR><BR>DO UNTIL RS.EOF ... LOOP<BR>vs.<BR>DO WHILE NOT RS.EOF ... LOOP<BR><BR>Thus saving one whole NOT. Maybe 20 nanoseconds? Maybe?<BR><BR>Oh...and I always use DO WHILE instead of just WHILE because you can do EXIT DO but there is no similar exit from a While...Wend. And since the byte codes are identical, why not?<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