This code is for Android but I guess anyone can take a chance at it.
It does what I want it to do. Just that I am not comfortable with its deep level of nesting and too much of value swapping.
Can this be optimized for readability or in compactness?
for(int imagenum, imagenum <76, imagenum++){
if (orientation.contentEquals("landscape")
|| orientation.contentEquals("reverse landscape")) {
params.height = imageheight;
params.width = imagewidth;
imageButton.setImageResource(R.drawable.imageback);
if (imagenum <= 38) {
params.leftMargin = imagenum * xspaceforeachimage;
params.topMargin = 0;
} else {
params.leftMargin = (imagenum - 39) * xspaceforeachimage;
params.topMargin = topMargin;
}
} else if (orientation.contentEquals("portrait")
|| orientation.contentEquals("reverse portrait")) {
params.height = imagewidth;
params.width = imageheight;
imageButton.setImageResource(R.drawable.imagebacklaid);
if (imagenum <= 38) {
params.leftMargin = 0;
params.topMargin = imagenum * xspaceforeachimage;
} else {
params.leftMargin = topMargin;
params.topMargin = (imagenum - 39) * xspaceforeachimage;
}
}
}
orientationhave? \$\endgroup\$String. \$\endgroup\$imagenum=75. \$\endgroup\$imageButtonandparamsare never reassigned inside your for loop, so they will result with whatever you give them in the last run of the loop. \$\endgroup\$