I want to fill a 2D array but it's not guaranteed to be filled entirely. Normally I would use a nested for loop, as follows:
for(i = 0; i < 10; i++)
{
for(j = 0; j < 10; j++)
{
array[i][j] = 1;
}
}
In this case I'm filling it entirely.
However, I don't know at first how many elements I have to put inside. I thought about a while
with a sentinel value, but then I should put inside a control statement to make sure the value won't exceed the size of the array, is that correct?
The code I put here is just an example, I'm actually curious about a different way to fill arrays since I've always seen for
or nested for
and I was wondering if there are other ways to do it. Thanks in advance.