This is not only an interesting question but an implementation of an historically significant algorithm. Warning: it is also an extremely poorly behaved pseudo-random number generator.
The algorithm is the middle-square PRNG due to John Non Neumann. To generate a sequence, one squares a four-digit seed and takes the middle four digits as the next element of the sequence. The while condition checks for the recurrence of an element.
The algorithm generates notoriously short sequences. The longest has 111 elements. If an element under 100 occurs, the sequence collapse to 0. If a multiple of 100 occurs, the sequence will show up to 5 more multiples of 100 and then quit.
Thanks for the interesting question, Steve