MPU-9250 + servo

Hello !
I use an mpu9250 and a servo.
I want to limit the servo travel, but I have a problem.
When I add each part in turn with -if-, it limits correctly, but when I put them together, it limits only one part, the bottom of the code.
What could be the cause please ..

   if (value <= 20) //
    {
      servo.write(20);//right
    }
    else
    {
      servo.write(value);  
    }

    if (value >= 150)
    {
      servo.write(150);// left
    }
    else
    {
      servo.write(value);
    }

20 is less than 150.

As they are written there ... each (separately) works fine. Together ..only one.
"value" is the indication of the magnetometer.

See post #2, then think it through.

   if (value <= 150) //
    {
      servo.write(150);//right
    }
    else
    {
      servo.write(value);  
    }

    if (value >= 20)
    {
      servo.write(20);// left
    }
    else
     {
      servo.write(value);
    }

It doesn't work that way either.
I tried all sorts of options ... the one posted first, at least works separately ...

I have another question ... can the magnetometer output be changed from 180-0 and 0-180 ... to 0 -360?
Thank you for the answers.

Magnetometers measure magnetic fields - where does the 0-180 stuff come from?

(But, yes, a set of values with those ranges can be very easily be remapped - the concept is called "arithmetic")

I solved it by changing the map, the problem remains with the limitation of the servo travel, left-right.
Thank you.

Re-read reply #2.
Try plugging some values into your code, and see what comes out

Hello !
I changed that ... Degree = (mpu.getYaw () + 180);
How many attempts did I make with the map, I forgot that I also tried the one with 0-360 degrees. The result displayed in the console, without moving the sensor ... the data is chaotic. Example ... if I set it to one degree ... the value increases and does not stop, just as if I set the sensor to 359 ... the values decrease continuously..I don't know how to try again.

That line doesn't appear in any code you've posted so far.
(Hint)

Degree = (mpu.getYaw () + 180);); //

The hint was meant to be a lot broader than that.

(Did that even compile?)

if( value <=150 && Value>20 ) might be something to think about doing.

Thank you for the answers.
1 - yes compiled.
2 - excuse me, I'll try, but if I don't solve with map 0-360, in vain I make the limitation work.

Please, you're just wasting everyone's time.

Excuse me, excuse me, I was wrong ....

Degree = (mpu.getYaw () + 180);

constrain: https://www.arduino.cc/reference/en/language/functions/math/constrain/

Thanks ..Dom.
...but if I don't solve map 0 to 360 compass, I make the limitation work in vain.

Before we make it to 100 replies (or even 30), it should be pointed out (again) that we can't see your code.