Question about while and DoWhile loops

Hey I have a question. In my scene whenever I do a while or doWhile loop the object teleports instantaneously. I want it to smoothly move toward the position. I though While loops iterates through each loop.

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{

    public GameObject pos1;
    public GameObject pos2;
    private float _distance;
    private Vector3 _direction;

    void Start ()
    {
        _direction = pos2.transform.position - pos1.transform.position;
        WhileLoop();
    }
       
    void WhileLoop()
    {
        do
        {
            pos1.transform.position += _direction * 1 * Time.deltaTime;
            _distance = Vector3.Distance(pos1.transform.position,pos2.transform.position);
        }
        while(Mathf.Abs(_distance) >= 5);
    }
}

What happens here is that it loops, but loops within a single frame (the start frame), so you only ever see it when the loop is over.

if you want something to move a step every frame, just use the Update() function, without the loop part.

using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
    public GameObject pos1;
    public GameObject pos2;
    private float _distance;
    private Vector3 _direction;
    void Start ()
    {
         _direction = pos2.transform.position - pos1.transform.position;
     }
      
    void Update()
    {
     
         if (Mathf.Abs(_distance) >= 5)
         {
              pos1.transform.position += _direction * 1 * Time.deltaTime;
            _distance = Vector3.Distance(pos1.transform.position,pos2.transform.position);
        }
       
    }
}

Thanks but is there a way to not use Update() method to do this? I manage to just use coroutine but is there a way to do through a regular method? Heres my updated code:

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
    public bool test;
    public GameObject pos1;
    public GameObject pos2;

    void Start ()
    {
       WhileLoop();
       //StartCoroutine("WhileLoopCoroutine");
    }
       
    void WhileLoop()
    {
        while(!Mathf.Approximately(pos1.transform.position.magnitude,pos2.transform.position.magnitude))
        {
            pos1.transform.position = Vector2.Lerp(pos1.transform.position,pos2.transform.position, 3 * Time.deltaTime);
        }
    }

    IEnumerator WhileLoopCoroutine()
    {

        while(!Mathf.Approximately(pos1.transform.position.magnitude,pos2.transform.position.magnitude))
        {
            pos1.transform.position = Vector2.Lerp(pos1.transform.position,pos2.transform.position, 3 * Time.deltaTime);
            yield return null;
        }
    }
}

Yeah, your coroutine code should work. just use that, and it will get updated every frame.

Its either coroutines or Update for every frame stuff. There is no other way.

OK thanks for the help. Really appreciate it.