changing "and" to "or" lead to high dynamic memory

Hi, So i had a perfectly working code (i am only posting part of it because it’s pretty long)
at this point the dynamic memory was at 31% but i had to change “&&” to “||”

for (pos=0;pos<=180;pos++){
  servo.write(pos);
  delay(50);
  digitalWrite(Trigger, LOW);
  delayMicroseconds(2);
  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trigger, LOW);
  duration = pulseIn(Echo, HIGH);
  distance = duration*0.034/2;
  curr_arr_duration_plus [pos] = distance;
  if(curr_arr_duration_plus [u]-arr_duration_plus [u]>2 && curr_arr_duration_plus [u]-arr_duration_plus [u]<-2){
    pos=181;
    On=1;}

and somehow that change made the dynamic memory skyrocket to 91%
i have 3 questions : why? , is there a way to fix it? and is it ok to use it anyway even though the IDE is saying “Low memory available, stability problems may occur.”
Thanks

Because, with the && you formed a conditional test that would always be false. No number can be both greater than 2 and less than -2. So the compiler optimized the code by not producing any code for it.

ok, makes sense
is it ok to use as it is?

and i suspect that the variable

curr_arr_duration_plus [pos]

is not being used anywhere else, so now the whole Array is being declared (and before just was optimized out) do you really need the whole array ? or is the value only used within the loop ?

Deva_Rishi:
do you really need the whole array ? or is the value only used within the loop ?

i do need the array but i could probably make it smaller by skipping a degree and making it pos +=2 instead of pos++

Without seeing the whole sketch, it's really impossible to give a definitive answer.

xunsus:
i do need the array but i could probably make it smaller by skipping a degree and making it pos +=2 instead of pos++

The question is do you need all 180 values ? (so you saying you could do with half of them ?)
And without the actual declaration it is a tad hard to tell what the variable type is, but i am assuming that it is 16-bit signed (integer type) and you probably will manage with an 8-bit signed (int8_t type) which will reduce the memory usage by half again.
As it is the 91% dynamic memory use is not getting you into trouble probably, but since you are still developing you program, and may get you into trouble later on, and it would be better to efficient now.