Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

object loop

Status
Not open for further replies.

gusset

Technical User
Mar 19, 2002
251
0
0
GB
i follow the advice to use the following syntax:

for each obj in collection.count
...
next obj

rather than

for i = 0 to collection.count -1
...
next i

because it is said to be quicker.

but if, with the first syntax, i stop code execution part-way through the loop, how can i examine which member of the collection the code has reached?

thanks

gusset
 
by the way, i know i could increment a variable. but is there some other way?

g
 
Well it would be:

for each obj in collection
...
next obj

>>how can i examine which member of the collection the code has reached<<

The properties of obj show which object in the collection is currently referenced. Are you talking about stopping execution in debug mode or exiting the loop when a condition is met?

Paul Bent
Northwind IT Systems
 
sorry, you're right - for each obj in collection (not collection.count).

i was indeed talking about debugging, but the question is equally applicable for an exiting condition.

the answer is the .index property, which i had forgotten about completely.

why is it faster?

thanks

gusset
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top