Is there a better way to do nested loops?

When something is clicked, you should usually be able to tell what was clicked directly. You should not have to look for it after you know it’s been clicked. What is being compared in hit == MotherNation.Value?

no because hit is just a string with nothing else v is the entire part with all the other values inside of it. anyways how does this question relate to optimization?

It relates because there is no better way than to use for loops IF you MUST look at every single value in one array for each and every value in another. There aren’t a whole lot of situations where that is really a must, relatively speaking. Redesigning your approach to avoid having to nest loops like that is most often the best route.

In short, there aren’t really better ways to do nested loops (could maybe flatten into a single array in some situations to get access to a value in one step…which isn’t as good as avoiding a loop), but there ARE often different approaches to a problem that can avoid the use of nested loops altogether.

If your goal is to find a way to avoid the lag spike, then explaining things in a way that allows someone to help design an approach that works is the best way to achieve that goal. If you are only interested in finding different ways to loop many tens of thousands of times then you may learn something new, but you won’t eliminate the lag spike that way.

Anyway, GL

1 Like