I was just experimenting with boolean operators as I haven't used them much before when I came up with something that has puzzled me. Its probably blatantly obvious to all but me, but here goes.
If I run this code:
int tim = 0;
void setup() {
pinMode(2, OUTPUT);
Serial.begin (9600);
}
void loop() {
Serial.println (tim);
// when variable 'tim' gets to each of the following values, flash led
if (tim == 0 || tim == 400 || tim == 600 || tim == 700 || tim == 750 || tim == 775 || tim == 785 || tim == 800 || tim == 810 || tim == 815 || tim == 817 || tim == 818 || tim == 819 || tim == 820 )
{
digitalWrite(2, HIGH); // turn the LED on
delay(10); // leave on for 10 ms
digitalWrite(2, LOW); // turn the LED off
}
tim++; // increment 'tim' by one
if (tim >= 821 && tim <= 2000) // when tim is between 821 and 2000
digitalWrite(2, HIGH); // turn the LED on
else
digitalWrite(2, LOW); // turn the LED off
}
it works exactly as I planned, a flashing led with decreasing increments between flashes then a long flash (its not for any project or anything, just experimenting)
However, if I comment out the serial print command, the led just flashes at a constant 1Hz - continuously.
My questions are
1 why does the commenting out of the serial print command affect, presumably, the count up of variable tim
2 How can I tidy up, use a more elegant way of expressing the line in which I specify the flash intervals?
Hope you can point me in the right direction.
Cheers
Bernie
Serial.println(tim) takes time however miniscule.
Well, without the Serial.print() the loop will run MUCH faster.
It's starting with130 milliseconds in delays (13 * 10) with the LED on and brief periods of counting in between. Then it turns the LED on for another 1179 loops. Since it appears to be blinking at 1 Hz and the integer counter overflows every 65536 counts the counting seems to be counting at about 75 kHz. The 1179 loops should take abut 15 milliseconds so the light should appear on for about 145 milliseconds and off for the rest of the cycle.
Ah, I see (he lied) - thanks guys.
By adding an extra delay of just 1ms in the loop makes the sketch work ok. I'm not 100% sure why yet, but I'll re-read your explanations in the morning when I'm not so tired and see if I can get my head around it.
I do now notice the wrap around of the integer counter illustrating itself by the sequence repeating itself every minute or so.
Once I understand the process more thoroughly, I'm going to rewrite the sketch using millis so its non-blocking. I'll no doubt find out for myself, but can you forsee the same effect occurring then?
Any ideas on how I could go about improving the if (tim == 400.... etc line? or is it ok "as is"? I was going to put some more interval values in it, so are we looking at using an array here do you think?
Many Thanks so far
Bernie
Ok, after waking up properly, I now understand the problem properly and can call the first question asked solved. For those as slow (or tired) as I, the explanation given by ieee488 and johnwasser expressed in simplistic terms is:
The loop is, well, looping at such high speed that the variable count 'tim' is so fast that there appears to be no visible time delay in the on/off control of the led, hence it is seen to flash only once. The wrapround of the counter accounts for the repeating seemingly single flash.
This also answers my own sub question in my first reply about the use of millis. I've yet to try it for real, but it seems obvious to me now that the problem won't arise when using millis because a unit that doesn't vary in length (ie the millisecond) would be being used as the yardstick and not a simple variable that can be updated at an unregulated rate (ok, not strictly accurate but you know what I mean). Just thinking out loud here so no-one else makes the same mistakes 
Still working on the second question.......
Cheers
Bernie