Question about algorithm https://www.shoup.net/ntb/ntb-v2.pdf, page 523, algortithm IPT

I don't get the for loop, since "k" isn't used anywhere inside the loop. What am i missing?
Just above the algorithm, the document says: 


  If $f$ is irreducible, then $\gcd(X^{q^k}−X, f) = 1$ for all positive
  integers $k$ up to $\ell /2$


What the loop does is just testing all the $\gcd(X^{q^k}-X,f)$ up to $\ell/2$. 

To avoid computing $X^{q^k}$ at each $k$, you just compute $X^{q^k}=(X^{q^{k-1}})^q=h^q$.

At the $k$-th round you will have $h=X^{q^k}$.