Time with do while()

this code doesn't do what I expected :

unsigned long lastMillis;
void loop(){
do {
getTime();
Serial.println(time);
lastMillis = millis();
}while(millis() - lastMillis >= 1000UL);
}

I expected that runs once and then before runs every second, that may be each 15 minutes, the condition allways is true because I get the time more than once in one second:

2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:37
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38
2.9.14. T 22:11:38

what is wrong?

you can do this:

void loop()
{
  if (millis() - lastMillis >= myInterval)
  {
    getTime();
    Serial.println(time);
    lastMillis = millis();
  }

and call getTime() in the setup() function.

I just change the do while for while loop and it works well, that tell me that the do while loop has a bug???

Thanks I'll apply the inner loop at the setup loop for the first time.

do while doesn't have a bug

you really want to stay away from blocking code like while loops....

I think you don't get the idea why the suggestion of BulldogLowell works and your don't, so try this code:

unsigned long lastMillis;
void loop(){
do {
getTime();
Serial.println(time);
lastMillis = millis();
delay (1000);
}while(millis() - lastMillis >= 10000UL);
}

and this:

void loop(){
do {
  if (millis() - lastMillis >= 1000UL)
  {
   getTime();
   Serial.println(time);
   lastMillis = millis();
   }
}while(millis() - lastMillis >= 10000UL);

}