I was struggling to find the right words for the title.
In my scenario, I have two indexes in a 2D array (x and y) that need to be multiplied together to determine the index for a second array (1D). However, it's not a straightforward calculation because if either x or y is zero, the result will always be zero no matter what the other value is.
One way to solve this problem is by using nested loops as shown below:
int count = 0;
for( int i = 0; i < x; i++ )
{
for( int j = 0; j < y; j++ )
{
count++;
}
}
//count now has the desired value
...but this solution seems very inefficient.
It feels like this should be a simple issue to resolve, and I've been avoiding asking about it until now, hoping it would turn out to be an easy fix.