Problem With Object Not Stopping To Move When Supposed To

I have a object. This object has a script attached to it called LegRRot. It is supposed to spin to a certain degree then go the other way to a certain degree and so forth. When I hit play, it rotates but doesn’t stop. Here is my code:

using UnityEngine;
using System.Collections;

public class LegRRot : MonoBehaviour {

	private bool forward;

	public float xPlus = -0.75F;

	public float xRotation;

	public float maxPosRot = 30f;

	public float maxNegRot = -30f;

	void Update() {

		if (xRotation <= maxNegRot) {
			forward = false;
		}

		if (forward = true) {
			xRotation += xPlus;
			transform.eulerAngles = new Vector3 (xRotation, 0, 0);

		} if (forward = false) {

			xRotation -= xPlus;
			transform.eulerAngles = new Vector3(xRotation, 0, 0);
		}


	}
}

If someone could provide some insight that would be greatly appreciated.

You seem to just be missing the case for setting forward to true.

using UnityEngine;

public class LegRRot : MonoBehaviour
{
	private bool forward;
	
	public float xPlus = -0.75F;
	public float xRotation;
	public float maxPosRot = 30f;
	public float maxNegRot = -30f;
	
	void Update()
	{
		if (xRotation <= maxNegRot)
			forward = false;
		else if (xRotation >= maxPosRot)
			forward = true;
		
		if (forward)
			xRotation += xPlus;
		else
			xRotation -= xPlus;
		
		transform.eulerAngles = new Vector3 (xRotation, 0, 0);
	}
}