EDIT: In most cases, you should avoid this, and rather follow the MSalter answer . Just because you can, it does not mean that you should.
I'm not sure how good the idea is, but without context, a simple solution might be:
int starts[3] = { ax, ay, az }; for ( int var = 0; var < 3; ++var ) { for ( int i = starts[var]; i != 0; --i ) {
Note that the condition values are obtained once at the beginning of the function, which means that if object a changes during the first cycle, this change will not be displayed in subsequent control loops. If you need it, the solution can be changed to store pointers.
EDIT : There is a comment suggesting the use of array size. I did not add that there is no change here, but in any case, the best way to get the size of the array:
template<typename T, unsigned int N> inline unsigned int array_size( T (&)[N] ) { return N; }
source share