I’m learning programming using Xojo with a program that I’ve inherited. This is more of an algorithm question than a Xojo question, but I hope that someone can help me.

I have a square array containing little squares of value s(i,j)=1 or s(i,j)=-1 whose color I would like to change to one of two possible colors. Basically, if s(i,j)=1 and s(i+1,j)=-1 then I’d like to have both of those squares be the same color, if s(i,j)=1 and s(i+1,j)=1 then both of those squares need to be different colors, etc. Then, I compare the next two squares, then the next two, etc. It gets a little tricky with an odd array (say, 3 x 3 or something) so I thought I’d start with an even array, as given below.

My questions are: is there a simpler way to code it? Naively, two for loops followed by three if statements doesn’t seem very efficient to me. Also, how do I specify in the case of, for example, s(i,j)=1 and s(i+1,j)=1 that those squares need to be two separate colors?

[code] Dim x, y, n as Integer

for i=0 to size-1

for j=0 to size-1

if size = 2 * n then // if even array (it gets tricky with an odd array)

if i = 2 * n then // comparing first two squares, then next two, etc.

if s(i,j)=1 and s(i+1,j)=-1 then

GraphicsWindow.Graphics.ForeColor = Color1

if s(i,j)=1 and s(i+1,j)=1 then

// ???

…

```
end if
end if
end if
next
```

next

x = i * SquareWidth

y = j * SquareWidth

GraphicsWindow.Graphics.FillRect x, y, SquareWidth, SquareWidth[/code]