add a new condition for lnum

In the while loop, the variable lnum should be larger than 0.
If not, the loop continues limitlessly.