Re: Nested loop with no overlap



gerard46 wrote:
) for (a1=0; a1<5; a1++)
) for (a2=0; (a2<5) && (a2!=a1); a2++)
) for (a3=0; (a3<5) && (a3!=a1) && (a3!=a2); a3++)
) ...etc.
)
) This should be a lot faster as all of the checks are done as
) the soonest possible time. _________________________Gerard S.

But it won't actually work, because the counter will never get past the
previous one. You want a 'if (a2 == a1) continue;' clause at the start of
the loop body.

Anyway, if you have five counters that all count five numbers, you're
basically working with permutations, and you're best off using something
tailored to that. For example, you can use an array of five elements where
the first (or last) N elements are those that haven't been chosen yet.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
.



Relevant Pages