Rotating to a certain degree and stopping?

I’m a bit new to unity and c# and I can’t manage to stop a rotation at a certain degree.

using UnityEngine;
using System.Collections;

public class RotateBase : MonoBehaviour {

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		    transform.Rotate (Vector3.up * 0.5f);

        if (Input.GetKey(KeyCode.LeftArrow))
            transform.Rotate(Vector3.down * 0.5f);

        if (transform.rotation.y > 45)
            transform.Rotate (Vector3.up * 0.0f);


When I press the left and right arrows it rotates all the ways around. I tried stopping the rotation when it hit 45 degrees but I have no clue how to do it.
All I know at the moment is basic C# code so if someone can show me how to make the rotation halt at 45 degrees when I’m pressing the right arrow and 315 degrees when I press the left arrow I would be very greatful. Try to keep it simple if you can please.

If I recall correctly, Unity uses quaternions as opposed to degrees. use Transform.eulerAngles to work in degrees.

Ya, sorry but I still don’t know how to stop the rotation at a certain degree.