Answer
Yes, it will work correctly. The quantity $(n - m + 1)$ evaluates to $1$. Since $k$ is initialized to $1$, the test $k \leq (n - m + 1)$ will initially evaluate to $True$ and the loop will be executed. The text and the pattern will be matched beginning at position $1$. Then when $k$ is incremented to $2$, the test will become $false$ and we will exit the loop, as desired.
Work Step by Step
Yes, it will work correctly. The quantity $(n - m + 1)$ evaluates to $1$. Since $k$ is initialized to $1$, the test $k \leq (n - m + 1)$ will initially evaluate to $True$ and the loop will be executed. The text and the pattern will be matched beginning at position $1$. Then when $k$ is incremented to $2$, the test will become $false$ and we will exit the loop, as desired.