Nested for... each statments
BlitzPlus Forums/BlitzPlus Programming/Nested for... each statments
| ||
Is is possible to put a For... Each loop inside another For... Each loop? Like this:For space.planet=Each planet For space.planet=Each planet ;yadda yadda yadda Next Next I need to do this because I have a bunch of things in a type that need to react to every other thing in the type, and therefore I need to ieterate through each thing in the type for each thing in the type. Oh, forgot to say: if I try this, it runs up untill the for...each loops, and crashes. But if I remove one for...each, then it "works" (it runs, but dosn't do what I want it to do.). |
| ||
For this.object=Each object ;The current object For other.object=Each object ;Check it against another object ;This if statement confirms that we're not comparing the object against itself, ;because in most instances, doing this will mess things up. If this.object<>other.object Then ;Do stuff Endif Next Next |
| ||
Umm... I'm not totally sure that's what I need. Here's the loop I am attempting to accomplish.For space.particle=Each particle For space.particle=Each particle space\x=space\x+Sgn(space\x-lastparticlex)*lastparticlemass space\y=space\y+Sgn(space\y-lastparticley)*lastparticlemass lastparticlex=space\x lastparticley=space\y lastparticlemass=space\mass Next Next I need to go through each thing in the type collection, then for each thing in the type collection, go through each thing in the same type collection. |
| ||
You can't have the same loop counter variable (space) in each loop in the nest or they will interfere. |
| ||
Yeah, usually I'll use:For space.Particle=Each Particle For space1.Particle=Each Particle do something Next Next |
| ||
Okay, it works now, now I just need to find a way to keep the things from flying off the screen... |