Yes, there is. The modulo (%) operators effectively track whether tiles are even or odd to fill them in alternating colours (in this case, red and white). So, you could add variables and if/else statements to keep track instead, but the code isn’t nearly as concise –
// variables to track if the column/row is odd or even
String odd_or_even_col = "even";
String odd_or_even_row = "even";
void draw() {
for (int m = 0; m < cols; m++) {
for (int n = 0; n < rows; n++) {
// code for coloring even columns with alternating tiles
if (odd_or_even_col == "even") {
if (odd_or_even_row == "even") { fill(255, 0, 0); odd_or_even_row = "odd"; }
else { fill(255); odd_or_even_row = "even"; }
}
// code for coloring odd columns with alternating tiles
else {
if (odd_or_even_row == "even") { fill(255); odd_or_even_row = "odd"; }
else { fill(255, 0, 0); odd_or_even_row = "even"; }
}
rect(m*x, n*x, x, x);
}
// alternate even/odd state for each column
if (odd_or_even_col == "even") { odd_or_even_col = "odd"; }
else { odd_or_even_col = "even"; }
}
}
Of course, there are other approaches too. For instance, you could avoid a loop-within-a-loop, opting for a single loop instead. This might make it easier to alternate colours (without using %), but there are other trade-offs.