boolean function

I’m trying to use a boolean function.

bool StatusNo[4] = {false, false, false, false}; 

void setup() {
  Serial.begin(9600);
}

void loop() {
   if (StatusActive() == false) {Serial.println("false");}
   else if (StatusActive() == true) {Serial.println("true");}
   delay(5000);
   StatusNo[3]=true; StatusNo[1]=true;}

bool StatusActive(){
  for (byte i = 0; i < sizeof(StatusNo); i++ ) {
      if (StatusNo[i] == false ) {return false;}}
  return true;}

Can someone explain why this isn’t working?

For what definition of "doesn't work". I'll posit that it does work and does exactly what the code says it should. If that doesn't meet with your expectations then you need to share the expectations.

As written it should always return false. Never true. You never set StatusNo[0] to true so the for loop will find a false on the first pass and the function will return.

It does work. It does exactly what you’d expect. It prints false if at least one of the elements in the array is false.

What makes you think that it doesn’t work?

Please use the auto-format in the IDE to make your code more readable.

bool StatusNo[4] = { false, false, false, false };

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (StatusActive() == false) {
    Serial.println("false");
  }
  else if (StatusActive() == true) {
    Serial.println("true");
  }
  delay(5000);
  StatusNo[3] = true; 
  StatusNo[1] = true;
}

bool StatusActive() {
  for (byte i = 0; i < sizeof(StatusNo)/sizeof(StatusNo[0]); i++ ) {
    if (StatusNo[i] == false ) {
      return false;
    }
  }
  return true;
}

Pieter

Both of you are right; I wasn’t clear enough. Sorry about that.
I expected it to return true if one of the elements is true.
I now understand why it didn’t. So i changed it to:

bool StatusNo[4] = {false, false, false, false};

void setup() {
  Serial.begin(9600);
}

void loop() {
   if (StatusActive() == false) {Serial.println("false");}
   else if (StatusActive() == true) {Serial.println("true");}
   delay(5000);
   StatusNo[3]=true; StatusNo[1]=true;}

bool StatusActive(){
  for (byte i = 0; i < sizeof(StatusNo); i++ ) {
      if (StatusNo[i] == true ) {return true;}}
  return false;}

Thanks.