Why dosen't this work?

I’m kinda new to Arduino so maybe I am missing something.
The if statement will not execute in this sketch. I know n = 0 every 10 minutes because I did a serial print just before the if statement.

n = minute % 10; //log data every 10 minutes
if (n = 0 ){ // time to log data?
logData(); // yes do it
}

But this one works!!!

n = minute % 10; //log data every 10 minutes
if (n < 1 ){ // time to log data?
logData(); // yes do it
}

OK so somebody tell me what’s wrong so I can look real stupid.

if (n = 0 )

if(n == 0)

common mistake

= assigns a value == compares it

if your fairly new to programing you can do it like (0 == n) that way if you mess up it should throw up an error, but if your in the habit of the other way its kind of hard to break

I knew somebody could make me look stupid!! cause I new about the difference between = & ==. It just didn't register. I'm more familiar with Visual Basic. Thanks for the reply. Case closed!

I knew somebody could make me look stupid!!

nah everyone does it, heck I did it not too long ago

good luck and have fun

nah everyone does it, heck I did it not too long ago

Very true, especially if you are swapping languages all the time, I have been known to do it myself. ;)

avr-gcc can warn you about such errors, -Wall or more specifically -Wparentheses would do it

Does anyone know a way to get the arduino IDE to pass options to gcc? ;)

A better way to do it (unless you need "n" for later calculations, in which case using it inside the if() compare is perfectly fine) would be:

if (!minute % 10) { // time to log data (every 10 minutes)?
  logData();            
}

If you -aren't- re/using "n" at a later point in the code, the above is better because "n" won't be taking up valuable memory space...

:)