Saturday 26 January 2008

Difficult to find if error

I just spent a little while resolving an error... and it turned out to be a stupid little syntax error.

I had written something similar to the following:

if(evaluate1evaluate2evaluate3&&evaluate4);
{
// Do Something
}

The error was that, even though I thought it shouldn't, the Do Something was always doing something.

I started looking into the evaluations in the if statement and trying to work out why they seemed to be evaluating to true when I thought they shouldn't be.....

Then I spotted the problem....

You might have spotted it straight away when you saw the statement above....

I had put a semi colon after the if statement, before the curly bracketed section I wanted to execute if the if evaluated to true.

Once I had seen it, it made perfect sense as to why the behaviour was happening and I could have kicked myself.

Definitely the first thing I will look for if I experience this behaviour again.

No comments: