Rotation control (C#)

Hello everyone!
I have an object which I rotate by mouse movement. The object’s rotation (axis x) increases when mouse moves up and decreases when the mouse moves down (I use Input.GetAxis (“Mouse Y”)). The problem I have is how to stop the rotation when it reaches a certain point, for example 200 degrees.

if (rotation.x < 200)  {
      object.transform.Rotate (mouseY, 0, 0);
}
   
else if (rotation.x >= 200) {
      if (mouseY < 0) {
              object.transform.Rotate (mouseY, 0, 0);
      }
}

With this code the value increases and decreases normally when it’s below 200, but when it comes above it can only be decreased. The problem is, when I move mouse fast enough the value stops at, for example, 205, instead of 200.
My question is, how to make the rotating stop exactly at number 200?
I’ve already tried many ways, such as slowing down the mouse movement, making the object rotate back or forcing the rotation to be exactly 200 when the value is over 200, etc. but these are only workarounds, which do not work perfectly and create a lot of bugs.

I want it to look like that:
rotation.x = 190
(mouse move up)
rotation.x = 200
(mouse move up)
rotation.x = 200
(mouse move down)
rotation.x = 190

Feel free to ask for details, I really appreciate any help!

You could avoid going over 200 degrees by checking if the “rotation to apply” would exceed the 200 degree limit and act accordingly.

To take your code example, it would look something like that:

if (rotation.x < 200)  {
 	if (mouseY > (200 - rotation.x)) {
		object.transform.Rotate (200 - rotation.x, 0, 0);
	} else {
		object.transform.Rotate (mouseY, 0, 0);
	}       
 	
 }
    
 else if (rotation.x >= 200) {
       if (mouseY < 0) {
               object.transform.Rotate (mouseY, 0, 0);
       }
 }

But this code would have a strange behaviour to my opinion. It would always rotate the object when you move the mouse down but would rotate only if angle < 200 when you move the mouse up. Maybe it fits in your case anyway. Hope that helps.