What is wrong with this if statement?

Have a simple program that I finally got working. I had to change a test.

This test: if lines[i][j] == cx {
works fine

Using this test: if (i != j) && (lines[i][j] == cx) {
the program fails.

Program is here: http://play.golang.org/p/fsOZNpkh3y
Tests are on lines 54 & 55

Using the bad test the nested for loop seems to wander off into the weeds about line 17 of the diagnostic output:
tx: O 2 3

I’ve posted some bone-headed mistakes here before. I hope this isn’t another one.

Your program is long and it’s not super clear what your if is supposed to be testing. There’s nothing wrong with either syntax wise, so this is a matter of the logic of what you’re trying to accomplish…

1 Like

Certainty was the problem. I was sure that the test was logically correct, but I was suspicious of the syntax. I keep tripping over problems with the syntax, like expressions need to be all on one line. So I was concerned that the expression (i!=j) didn’t mean what I thought it meant, and completely overlooked the problem that the center of the 3 by 3 block I was testing wasn’t at (i, j). Doh! Thanks for attention.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.