Sorry. I haven't been expressing myself very well, even to myself, today. I cobbled together some code that works. The sample code I gave is an excerpt of it. I'm just wondering if there is a more efficient way to do what I want to do.

What I want to do: loop through every combination of k selected vectors on a subset of R

^{N} that contains 2

^{N} vectors.

How my code does what it does: it assigns each vector a number from 0 to 2

^{N}-1. Nested while loops (k of them) are used to do the iterating. As it is, I need to increase the number of nested while loops if I want more vectors (up to 2

^{N-1}, of course - more vectors and the situation is the complement of a situation with fewer vectors.) A simple example of my while loop nesting:

Code: Select all

`a = 1;`

while(a < 4)

{

b = a+1;

while(b < 5)

{

c = b+1;

while(c < 6)

{

do_stuff(a,b,c);

c++;

}

b++;

}

a++;

}

will do stuff to (1,2,3), (1,2,4), (1,2,5), (1,3,4), (1,3,5), (1,4,5), (2,3,4), (2,3,5), (2,4,5), and (3,4,5).

What I want to know: is there a better way to do this? More specifically, would for be better than while? And is there a more general way to represent the vectors so that I don't have to rewrite code when I go to a higher dimension or increase the number of selected vectors? Since I have my code working right now, I don't need to know for now, but maybe for future reference.