exit(0) function shows up an error So I have been trying to write a code where I use the millis() function to print the milliseconds of on-time of the board using Serial. But the condition is I want to stop printing the value once it reaches 10 seconds (10000ms).

I have been trying to use the exit() function but I get no output then. 

#include&lt;stdlib.h&gt;

void setup()
{

  Serial.begin(9600);          //  setup serial


}

void loop()

{

unsigned long timer1;

while(timer1%10000!=0)

{

timer1=millis();

Serial.println(timer1);

}

    exit(1);

}
The AVR library documentation for exit() is great help. It explains that the interrupts are turned off and an infinite loop is entered. As the interrupts get turned off the last characters in the Serial buffer are not transmitted. 

You can use Serial.flush() to wait for the transmission to complete before calling exit(). 

Cheers!