Answer the question
In order to leave comments, you need to log in
Why is the loop behaving so strangely?
In general, there is a loop within a loop that manipulates two-dimensional matrices:
for(int i = 0; i < x; ++i) {
for(int j = 0; j < y; ++j) {
int x1 = i, y1 = j;
if(((abs(x1 - GO.x) == 1) || (abs(y1 - GO.y) == 1)) && *(desk+x1+y1))
GOnbr[i][j] = abs(STAY.startX - x1) > abs(STAY.startY - y1) ? x-abs(STAY.startX - x1) : y-abs(STAY.startY - y1);
else
GOnbr[i][j] = 0;
if((i - STAY.x >= -1 && i - STAY.x <= 1) && (j - STAY.y >= -1 && j - STAY.y <= 1) && !(i - STAY.x == 0 && j - STAY.y == 0) && *(desk+i+j))
STAYnbr[i][j] = 0;
else
STAYnbr[i][j] = 1;
GOnbr[i][j]*=STAYnbr[i][j];
cout << j << ' ' << i << endl;
}
}
...
0 0
1 0
2 0
0 1
1 1
2 1
0 2
1 2
2 2
0 3
1 3
2 3
0 0
1 0
2 0
0 1
1 1
2 1
0 2
1 2
2 2
...
Answer the question
In order to leave comments, you need to log in
For such a code, I hope it does not repeat itself?
#include <iostream>
int main()
{
int x = 3;
int y = 3;
for(int i = 0; i < x; ++i)
{
for(int j = 0; j < y; ++j)
{
std::cout << j << ' ' << i << std::endl;
}
}
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question