if statement without else

I am using this code to make an alarm clock.

void setup () {
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
  // Check to see if the RTC is keeping time.  If it is, load the time from your computer.
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // This will reflect the time that your sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

I don't quite understand why the if statement also includes what to do when the criteria are not met. I would write the script like this:

void setup () {
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
  // Check to see if the RTC is keeping time.  If it is, load the time from your computer.
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
  else {
    // This will reflect the time that your sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

Both versions seem to work but I don't see how the first one does. Can someone explain it to me?

You only want to set the clock when it is not set, don't you?

The second variant will overwrite a probably valid time with the time the sketch was compiled and leave the time unset if it was not set before.

steveinaustria:
I don't quite understand why the if statement also includes what to do when the criteria are not met.

It just does not. Nothing big to understand.

What I fail to understand is why in the first script the RTC.adjust(DateTime(__DATE__, __TIME__)); appears within the if (! RTC.isrunning()) {} statement. If the RTC is not running then surely there is no need to do anything except warn the user that the RTC is not running.

There is only a need to adjust the DateTime if the RTC IS running.

'running' in this context means 'has a valid time and date',
so if the RTC does not have a valid time and date it should be set.

Reread my previous post.

So the RTC date and time is set with RTC.begin(); is it? I hadn't realised that.

What happens if the RTC battery is dead? That is what I had equated "RTC not running" with.

steveinaustria:
So the RTC date and time is set with RTC.begin(); is it? I hadn't realised that.

No. begin just calls wire.begin() - does nothing to set the time.

The adjust call sets the clock running.

RTC's have an enable bit that needs to be set for the clock to run. If its running its assumed
the time is correct, else its assumed this is the setup phase, so the time needs to be set and
the RTC set running.