for loop question [newbie]
in
Programming Questions
•
3 years ago
Hi,
I'm trying to reduce this block into a more "elegant" one:
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][10] == 1) {
- dotMatrix[o][190] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][30] == 1) {
- dotMatrix[o][170] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][50] == 1) {
- dotMatrix[o][150] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][70] == 1) {
- dotMatrix[o][130] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][90] == 1) {
- dotMatrix[o][110] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][110] == 1) {
- dotMatrix[o][90] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][130] == 1) {
- dotMatrix[o][70] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][150] == 1) {
- dotMatrix[o][50] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][170] == 1) {
- dotMatrix[o][30] = 1;
- }
- }
- for (int o = 10; o <= 190; o = o+20) {
- if (dotMatrixSave[o][190] == 1) {
- dotMatrix[o][10] = 1;
- }
- }
Like this one, which by the way does not work...
- for (int y = 10; y <= 190; y = y+20) {
- for (int z = 190; z >= 10; z = z-20) {
- if (dotMatrixSave[y][y] == 1) {
- dotMatrix[y][z] = 1;
- }
- }
- }
I'm sure the solution is very simple, but I haven been able to fix it.
Any help will be welcomed....
Thanks.
1