Arduino Serial.println() keeps transmitting data even when conditions are imposed I am using Arduino UNO and a bluetooth module.  I have used an if condition so that Serial.println() happens only once but it keeps on printing.  Please help. Below is the code.

//Begin CODE
char str;
String fnal;
int i;

void setup()
{
  Serial.begin(9600);
  fnal="";
  i=0;
}

void loop()
{
  i++;
  if(i&lt;2)
  {
    Serial.print('#');
    Serial.print('1');
    delay(10);
  }
}


According to this code # and 1 should be printed only once but in serial monitor the printing continues infinitely.
If you had put a Serial.print inside loop you would have seen the problem. Debugging displays are very helpful. Like this:

void loop()
{
  i++;
  Serial.println (i);   // &lt;---- debugging
  if(i&lt;2)
  {
    Serial.print('#');
    Serial.print('1');
    delay(10);
  }
}


Since you are adding 1 to i each time around the loop, how long do you think it will go before i overflows? It will go up and up, get to 32767 and then become -32768, and then count back to 0. During that time it will be less than 2, and it will do the printing of "#1".