Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the difference between 2d array

Tags:

java

arrays

I'm wondering what is the difference between these loops in 2D arrays:

for (int r = row - 1, c = column - 1; r >= 0 && c >= 0; r--, c--) {
    ...
}


for(int r=row-1;r>=0;r--){    
    for(int c=column-1;c>=0;c--){
        ...
    }
}
like image 219
J.Cool Avatar asked Dec 06 '25 14:12

J.Cool


1 Answers

for (int r = row - 1, c = column - 1; r >= 0 && c >= 0; r--, c--)

The first example is one loop that decrements both r and c every cycle, meaning that the indices r and c will draw a diagonal starting at array[row-1][column-1]. enter image description here

for(int r=row-1;r>=0;r--){
    for(int c=column-1;c>=0;c--){

The second example calls a loop for columns for each index of row, so it will access all the indices array[r][c]
enter image description here

like image 125
Maljam Avatar answered Dec 08 '25 02:12

Maljam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!