I keep going through a two dimensional array and would like to stop repeating the same nested for loops
for (int x = 0; x < width; x++) {
for (int y =0; y < height; y++) {
// Do some stuff
}
}
Is there a way to DRY-out the nested for loops to something more along the lines of
iterateThroughMatrix ( doSomeStuff )
iterateThroughMatrix ( doSomethingElse )
iterateThroughMatric ( doSomeOtherStuff )
void iterateThroughMatrix ( doSomething ) {
for (int x = 0; x < width; x++) {
for (int y =0; y < height; y++) {
// doSomething here
}
}
}