Issue with logic on while loop clause

IDE 1.8.19

I am sure I have had this issue more than once and worked arround it , but it's bugging me... No mater what I try , I can't get a logical "or" "||" to work , adding extra () does not help. It compiles ok, uploads ok but when a clause is met, it does not seem to do anything, it never drops out of the loop and just keep decrementing.

the below is just a test code , I know my IDE is out of date but this seems fairly fundamental.

TIA..

Rob

int step1 = 100;
int step2 = 50;

void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  while ( step1 != 0 or step2 != 0  ) {
    Serial.println(step1);
    Serial.println(step2);
    step1--;
    step2--;
    delay(300);
  }
  delay (5000);
  Serial.println("zero");
  step1 = 100;
}

Yes, reading your code, that's exactly what I would expect. The loop would only stop if both variables are zero at the same time, which is never.

Look up DeMorgan's law...

while ( step1 != 0 or step2 != 0  ) {

is the same as

while ( not(step1 == 0 and step2 == 0)  ) {

Would you ever expect the loop to stop with that test?

What did you want it to do?

Indeed. This is how C code works, how logic works, nothing to do with the version of the IDE.

Perhaps you meant to use and ?

The issue with your while loop condition is that you're using or (||) instead of and (&&). Currently, the loop will continue as long as either step1 or step2 is not zero. If you want the loop to stop when either variable reaches zero, you should use and (&&).

Here's the corrected version:

int step1 = 100;
int step2 = 50;

void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  while (step1 != 0 && step2 != 0) {  // Changed 'or' to 'and'
    Serial.println(step1);
    Serial.println(step2);
    step1--;
    step2--;
    delay(300);
  }
  delay(5000);
  Serial.println("zero");
  step1 = 100;
}

The loop will now stop when either step1 or step2 reaches zero

&& ... yes both constrains need to be true to maintain the loop.

It's been a long week.

Thanks all..