How to move object grid base continuously?

I want to move object continously when I press button just once grid to grid. When I press button to make object move to another direction, it should wait until object is right on the grid and starts to move another direction. Those are my codes. It moves continously when I press once but doesn’t move grid to grid

void GridMove()
    {
        Debug.Log("ye");

        if(Input.GetKeyDown(KeyCode.W))
        {
            forward = true;
            back = false;
            left = false;
            right = false;

        }


        
        if (forward)
        {
            StartCoroutine(MoveCharacter(Vector3.forward * Time.deltaTime));
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            back = true;
            forward = false;
            left = false;
            right = false;


        }


        if (back)
        {
            StartCoroutine(MoveCharacter(Vector3.back * Time.deltaTime));
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            left = true;
            back = false;
            forward = false;
            right = false;
            

        }


        if (left)
        {
            StartCoroutine(MoveCharacter(Vector3.left * Time.deltaTime));
        }


        if (Input.GetKeyDown(KeyCode.D))
        {
            right = true;
            back = false;
            forward = false;
            left = false;


        }


        if (right)
        {
            StartCoroutine(MoveCharacter(Vector3.right * Time.deltaTime));
        }












    }


    private IEnumerator MoveCharacter(Vector3 direction)
    {
        

        float elapsedTime = 0f;

        originPos = transform.position;
        targetPos = originPos + direction;


        while (elapsedTime < timeToMove)
        {
            transform.position = Vector3.Lerp(originPos, targetPos, (elapsedTime / timeToMove));
            elapsedTime += Time.deltaTime;
            yield return null;
        }


        transform.position = targetPos;



        
    }

In general, after looking at your code, I thought that a different approach is needed here. In the following script, I did something like what you need. Comments in the script can help to understand.

using UnityEngine;

public class CubeMovingOnGrid : MonoBehaviour
{
    //It is much easier to use a direction vector
    //than four bool variables and four conditions.
    Vector3 movingDirection = Vector3.forward;

    //We use end position to snap to grid.
    Vector3 targetPosition;

    float timeToMove = 5f;
    float elapsedTime;

    //Grid cell size
    public float lengthCellGrid = 1;
    public float speed = 1;

    void Start()
    {
        targetPosition = transform.position;
    }

    void Update()
    {
        GridMove();
    }

    void GridMove()
    {
        elapsedTime += Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.W))
        {
            movingDirection = Vector3.forward * lengthCellGrid;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            movingDirection = Vector3.back * lengthCellGrid;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            movingDirection = Vector3.left * lengthCellGrid;
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            movingDirection = Vector3.right * lengthCellGrid;
        }

        // Shift targetPosition if we got to it
        if (targetPosition == transform.position && elapsedTime < timeToMove)
        {
            targetPosition += movingDirection;
        }

        // Moving to targetPosition
        transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
    }
}