While loop causes game to freeze

I have a while loop that is intended to trigger when the player character (which the code in question is attached to) moves out of view of the main camera and move the camera in the proper direction until the player character is once again in view of the camera:

	private void MoveCamera()
	{
		Vector3 lowerLeft = playerCamera.ViewportToWorldPoint(new Vector3(0, 0));
		Vector3 upperRight = playerCamera.ViewportToWorldPoint (new Vector3(1, 1));
		bool left;
		bool up;
		bool right;
		bool down;

		while (!r.isVisible) {
			Debug.Log ("Still off the screen");

			// Determine what sides of the screen the player is off
			if (transform.position.x <= lowerLeft.x) {
				left = true;
			} else {
				left = false;
			}
			if (transform.position.y <= lowerLeft.y) {
				down = true;
			} else {
				down = false;
			}
			if (transform.position.x >= upperRight.x) {
				right = true;
			} else {
				right = false;
			}
			if (transform.position.y >= upperRight.y) {
				up = true;
			} else {
				up = false;
			}

			// Determine where to move the camera
			if (up && right) {
				cameraEndPoint.Set (cameraStartPoint.x + 0.1f, cameraStartPoint.y + 0.1f, cameraStartPoint.z);
			}
			else if (down && right) {
				cameraEndPoint.Set (cameraStartPoint.x + 0.1f, cameraStartPoint.y - 0.1f, cameraStartPoint.z);
			}
			else if (down && left) {
				cameraEndPoint.Set (cameraStartPoint.x - 0.1f, cameraStartPoint.y - 0.1f, cameraStartPoint.z);
			}
			else if (up && left) {
				cameraEndPoint.Set (cameraStartPoint.x - 0.1f, cameraStartPoint.y + 0.1f, cameraStartPoint.z);
			}
			else if (up) {
				cameraEndPoint.Set (cameraStartPoint.x, cameraStartPoint.y + 0.1f, cameraStartPoint.z);
			}
			else if (right) {
				cameraEndPoint.Set (cameraStartPoint.x + 0.1f, cameraStartPoint.y, cameraStartPoint.z);
			}
			else if (down) {
				cameraEndPoint.Set (cameraStartPoint.x, cameraStartPoint.y - 0.1f, cameraStartPoint.z);
			}
			else if (left) {
				cameraEndPoint.Set (cameraStartPoint.x - 0.1f, cameraStartPoint.y, cameraStartPoint.z);
			}

			// Actually move the camera
			playerCamera.transform.position = Vector3.Lerp(cameraStartPoint, cameraEndPoint, (Time.time - startTime) / duration);

			// Reset camera start point
			cameraStartPoint.Set(cameraEndPoint.x, cameraEndPoint.y, cameraEndPoint.z);
		}

When I change the while loop to an if statement, the code executes properly, but only once. I want the code to execute until the player character is once again in view of the camera; what am I doing wrong? Thanks!

Maybe you should make things work a bit different?

    if (!r.isVisible)
        {
            //Do yor stuff about detecting where the player
        }

    while (!r.isVisible)
        {
            //Move the camera before player appears again
        }

keep it as an if statement and place your iterations in
void Update (){} ;

I’d say void Update(){ MoveCamera();}