For in For or larger For?

Hello!

Quick question, more like a curiosity.

From a performance point of view, is it better to use a larger for rather than 2 nested fors ? I assume the difference in performance is negligible anyway.

For example (nested for):

for (int i = 0; i < m_groups.Length; i++)
            for (int j = 0; j < m_groups*.coins.Length; j++)*

// stuff here
(and larger for)
for (int j = 0; j < m_positions.Length; j++)
// stuff here, but m_positions.Length = all m_groups.coins.Length
Thank you!

One loops over an array, the other loops over an array of arrays - performanse-wise, they’re identical.
You should choose the method that best describes how your data is structured. i.e. are your coins actually placed in logical groups? If so, option 1 is fine. But, if not, don’t introduce artificial groups into your data structures for the purposes of a for loop.

It’s the same. You can tested your self.