how to tell if a for loop has completed

I’ve been having trouble with for loops.

I’ve created a simple for loop that decides how far my units move

 for (int i = 0; i < moveSpeed; i++)  {
         //moves unit
         if (i == moveSpeed) {
                  path = null;

My problem is that the path is not cleared. And I’m too dumb to figure it out.
Is there any way to tell if the loop has ended and act on that information?

i will never be equal to movespeed. Your condiction is i < movespeed (which excludes the equal condition). In the last iteration of your loop, i will be equal to (moveSpeed - 1). Check against that or just set path to null after the for loop, no conditions.