Login    New User    Forgot Password    Help      

Using arrays with Loops

GO TO INDEX

Using arrays with Loops

Arrays appear to be nothing more than normal variables until you use them with loops. You can initialize all the elements of an array to 0 using a loop instead of setting them each individually.

int arr[3];
for (int x=0; x<3; x++)
   arr[x] = 0;

When you do this with a 2D array you need to use 2 loops.

int arr[3][3];
for (int x=0; x<3; x++)
   for (int y=0; y<3; y++)
      arr[x][y] = 0;

GO TO INDEX