
Still Need FOR LOOP Help
Here is some code: <BR><BR>For count=1 To thePeople(0) <BR>If Cint(count)<>Cint(Session("POS")) Then <BR>For x2=1 To numMatches <BR>If matchValues(count)>=yourMatches(2,x2) Then <BR>For x3=numMatches To x2+1 Step 1 <BR>yourMatches(1,x3)=yourMatches(1,x31) <BR>yourMatches(2,x3)=yourMatches(2,x31) <BR>Next <BR>yourMatches(1,x31)=count <BR>yourMatches(2,x31)=matchValues(count) <BR>End If <BR>Next <BR>End If <BR>Next <BR><BR>Basically I am working with a 2D array here. The first for loop goes through all of the people in the database where thePeople(0) is the number of people following. We don't want to compare the user to his/herself, so if its a different person then we do the code. <BR><BR>For x2=1 To numMatches goes through 3 positions in the 2D array (as numMatches is set to 3) and if that persons value from another array is greater than or larger than what is stored in the 2D array, I want it to sort the rest down (ie, pos 3 goes to pos 2, 2 to 1) and the first place is replaced with new info. (3 is an example, it is a varying number depending on the amount of users so I must be using a loop form and not just code) <BR><BR>So basically what I need is a way to exit that loop with x2 because if I don't this is what will happen: <BR>Let's say the array is this to start: <BR>23 <BR>20 <BR>17 <BR>It will go through once and replace the new value (lets say its 40) into the top and move everything down (losing the last pos) <BR>40 <BR>23 <BR>20 (that works( <BR>But if I don't cancel the loop it will go again checking to see if its greater than the second position and so on and so forth thus filling 40 in the entire array. <BR>======================<BR>The help I have received said use Exit For, but that canceles both the inner and outer for. Any suggestions?<BR><BR>Thanks,<BR>Jordan

I believe you are mistaken
Exit For does *not* cancel any FOR loop except the innermost one that is *CURRENTLY* executing.<BR><BR>So in your code:<BR><BR>For count=1 To thePeople(0) <BR> If Cint(count)<>Cint(Session("POS")) Then <BR> For x2=1 To numMatches <BR> If matchValues(count)>=yourMatches(2,x2) Then <BR> For x3=numMatches To x2+1 Step 1 <BR> yourMatches(1,x3)=yourMatches(1,x31) <BR> yourMatches(2,x3)=yourMatches(2,x31) <BR> IF WHATEVER THEN EXIT FOR ' exits only x3 loop<BR> Next <BR> yourMatches(1,x31)=count <BR> yourMatches(2,x31)=matchValues(count) <BR> End If <BR> IF WHATEVER THEN EXIT FOR ' exits x2 loop<BR> Next <BR> End If <BR> IF WHATEVER THEN EXIT FOR ' exits x1 loop<BR>Next <BR><BR>SO maybe you are just putting the exit for in the wrong spot in your code???<BR><BR>You *may* need to set a flag and then exit based on the flag.<BR><BR>Could you name your FOR loop variables something more enlightening than x1, x2, x3? It might make what you are trying to do more understandable. (I'm a little lost.)<BR><BR>

Looks to me like...
...you probably want the Exit For just before the next to last "END IF" statement?<BR><BR>For count=1 To thePeople(0) <BR> If Cint(count)<>Cint(Session("POS")) Then <BR> For x2=1 To numMatches <BR> If matchValues(count) >= yourMatches(2,x2) Then <BR> For x3=numMatches To x2+1 Step 1 <BR> yourMatches(1,x3)=yourMatches(1,x31) <BR> yourMatches(2,x3)=yourMatches(2,x31) <BR> Next <BR> yourMatches(1,x31) = count <BR> yourMatches(2,x31) = matchValues(count) <BR> Exit For ' this will break out of x2 loop!<BR> End If <BR> Next <BR> End If <BR>Next <BR><BR>

RE: Looks to me like...
Thanks. You are always a help.<BR><BR>I am pretty sure I was putting it in the right spot but I will give it a try again.<BR><BR>It is kind of hard to explain because of the way my info is stored. x2,x3 are just meant to be counters just like 'i' and 'count' are...<BR><BR>Thanks, I'll give it a whirl.<BR><BR>Jordan

RE: Looks to me like...
FIXED IT!<BR><BR>It was part some design flaw and part fiddling around with some code. I eventually got it working using a conditional to end the For Loop. Thanks for the help!<BR><BR>Jordan
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

