So I've been trying to do some code simplification, mainly because I'm not that fond of having Nested For loops however I'm experiencing trouble trying to simplify the below code. The code does functions perfectly fine and does as intended (code below is stripped down!).
int fill{200}, wid{600}, hei{400};
for (int w{ 0 }; w < fill; w++) {
for (int h{ 0 }; h < hei; h++) {
int offset{ w + h * (wid + fill) }
//Offset is used to traverse a 1d array "fill" amount of times.
/*Before:
000000
000000
000000
000000
After:
110000
110000
110000
110000*/
}
}
I've tried to reproduce the same output with 1 less Loop but I either don't get the right result or I go outside of the array. So I'm wondering can it be done?