function RETURN for power on self test

//Init Sensors
void initSensors(){
  
  //Indoor Sensor Init
  ds1.reset_search();
  if ( !ds1.search(ds1_addr)) {
    debug.println(F("No more Indoor Sensor"));
    bla bla bla
    return;
  }
  
  debug.print(F("Indoor Sensor ADDR ="));
  //printed sensor addr

  if (OneWire::crc8(ds1_addr, 7) != ds1_addr[7]) {
      debug.println(F("Indoor Sensor CRC is not valid!"));
      return;
  }

  bla bla bla 
  
  //Outdoor sensor init
  ds1.reset_search();
  if ( !ds1.search(ds1_addr)) {
    debug.println(F("No more Indoor Sensor"));
    bla bla bla
    return;
  }
  
  debug.print(F("Indoor Sensor ADDR ="));
  //printed sensor addr

  if (OneWire::crc8(ds1_addr, 7) != ds1_addr[7]) {
      debug.println(F("Indoor Sensor CRC is not valid!"));
      return;
  }
 
}

This is what i have (made it small intentionally as the code is available online and to keep it simple. What I need is a POST function, a power on self test. To achieve this, I am planning to have several bool function and on each bool function, POST will get some score.... My approach is:

void PowerOnSelfTest(void) {
  int totalPOSTs = 1; //Change it when new POST items added.
  int POSTcode = 0;

  //Below put all the POST jobs
  if (initSensors()) {
    //Assumed a POST is success, hence update the POSTcode
    POSTcode = POSTcode + 1;
  }

  //since all PSOT jobs done, let's evaluate.
  if (POSTcode >= totalPOSTs) { //POST found no error
    errorCode = 0;
    debug.println(F("POST Successful.\n"));
  }
  
  else if (POSTcode < totalPOSTs) { //Surely there is a POST failure
    errorCode = 1;
    processError();
  }
  
}

So the above I hope is easy to understand... at this stage, I am planning to modify the initSensors() function to boolean type and to return TRUE if all is okey. here I can see a piece of code saying "return"

if ( !ds1.search(ds1_addr)) {
    debug.println(F("No more Indoor Sensor"));
    bla bla bla
    return;
  }

But i'm confused, NO more sensor means a disconnected sensor and it should give false. But on giving false, (since the list is long, 2 sensors and more possible errors) the function will keep going after that "if" or function will exit? Because I need to see errors as debug as well as a POST failure.

Will this "return" simply exit the IF section or the entire function or it will update the status of the boolean function while keep going till the end of the function? And in that case, for the bool to be successful should I change the "RETURN" to "RETURN FALSE" and add a "RETURN TRUE"? at final? I'm fully confused...

TIA

any idea guys???

return causes the program to immediately return to the place the function was called from

If you need to iterate through a number of sensors and return true or false depending if any of them fail then set a boolean variable, let's name it sensorsOK to true on entry to the function and set it to false if any of the sensor initialisations fail and return the value of sensorsOK to the calling program at the end of the function

If it is important that the calling program can determine which sensors passed or failed then consider setting different bits in an integer variable to 0 or 1 to indicate pass or fail of individual sensors and return that. The calling program can then examine the returned variable to determine how many and which sensors failed to initialise

wouldn't you like to know which test failed?

another approach would be to set a corresponding bit in a result variable when a test fails. if the result is zero, Pass, otherwise Fail and report the result which indicates which and how many tests failed.

gcjr:
wouldn't you like to know which test failed?

Yep!!

I am not sure if this method will work:::

Do test, and on failure, printout as debug. [this will tell me which test failed]
keep going with a flag (my incremental number)
As the individual number was supposed to be 1 but found 0, then reporting again that XYZ test failed.
And finally as total test = incremented number, POST success. Or else POST failed.

What do you think??

//Init Sensors
void initSensors(){
 
  //Indoor Sensor Init
  ds1.reset_search();
  if ( !ds1.search(ds1_addr)) {
    debug.println(F("No more Indoor Sensor"));
    bla bla bla
    return; //RET#1.1
  }
 
  debug.print(F("Indoor Sensor ADDR ="));
  //printed sensor addr

  if (OneWire::crc8(ds1_addr, 7) != ds1_addr[7]) {
      debug.println(F("Indoor Sensor CRC is not valid!"));
      return; //RET#1.2
  }

  bla bla bla
 
  //Outdoor sensor init
  ds1.reset_search();
  if ( !ds1.search(ds1_addr)) {
    debug.println(F("No more Indoor Sensor"));
    bla bla bla
    return; //RET#2.1
  }
 
  debug.print(F("Indoor Sensor ADDR ="));
  //printed sensor addr

  if (OneWire::crc8(ds1_addr, 7) != ds1_addr[7]) {
      debug.println(F("Indoor Sensor CRC is not valid!"));
      return; //RET#2.2
  }
 
}

For this code can you explain the flow of the RET#x.x (for my really broader understanding, and hence to dilute the confusion)

The standard approach is to have an initialization routine return a bool success/fail flag. When you do the init, you test the flag and if it is a fail, print an error message and go into an endless while(1).

I'm just wondering, why that is not good enough for you.

can u give a sample?

aarg:
Print an error message and go into an endless while(1).

I'm just wondering, why that is not good enough for you.

Well, I was thinking it a bit different way, if the POST/Init fails, it will surely give an error but it will also ask me if I want to go one... if I say "Y" then it will run taking the errors into count (means sensorless goahead) and if "N" (default) then well, stay here silent and do nothing.