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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Loops

Status
Not open for further replies.

snorky

Programmer
Jun 5, 2001
58
GB
Newbie question

I have 2 nested loops
for x= 0 to 10
for y = 11 to 23
do something
Next - here I want to increment x AND y at the same time
how do I do that - Next x,y ? ? ? ?

Thanks
 
Looks like it is not a nested loop, just moving two vaiables at the same time but X has 11 values while y has 13.
What's up
Code:
Y = 11
for x = 0 to 10
    do something
    Y = Y + 1
Next
' Y(22) and Y(23) are unprocessed
Or
Code:
for x = 0 to 10
    for Y = 11 to 23 ' Process all Y for each X
        do something
    Next
Next
 
Oops - yeah that was a typo ! I wanted to process the x's and y's at the same time ( so when Next arrived x ANd y incremented ) and thought I had seen a command similar to Next x,y
But I'll try your suggestion of using Y=Y+1 instead
Many Thanx !

Snorky
 
From looking at what you want to do, you probably have an array that has an upper and lower group of things you want to keep together.

ie, you might want to keep customer names with their phone numbers. So you allocate the lower 11 locations to Customer Names and the Upper 11 to their phone number.

Name, Phone

Customer(0) = "Steve"
Customer(11) = "Steve's phone number"
Customer(1) = "Don"
Custoemr(12) = "Don's phone number"

To express it mathematically when you think about it Y is really x + 11. So the following code should do the trick. Whenever you want the value of y, just add 11 to the value of x. Like this:

For x = 0 To 10
Debug.Print Customer(x), Customer(x+11) 'Name, Phone
Next x Snaggs
tribesaddict@swbell.net
To define recursion, we must first define recursion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top