Confused about constructing the "failure table" in Knuth-Morris-Pratt algorithm
A proper prefix, which is also a suffix of the same string, is usually called border.

The condition you're asking about basically says this:


If $W[1..i-1]$ has a border of length $j$ and $W[j+1] = W[i]$, then $W[1..i]$ has a border of length $j+1$.
If $W[1..i-1]$ has no border of length $j$ such that $W[j+1] = W[i]$, then the length of the maximal border of $W[1..i]$ is $0$.


Both points follow directly from definition of string equality and definition of borders.

What you need to prove is that the while-loop indeed enumerates all possible borders in descending order.