Seems to me that you will be stuck in an infinite loop anyway since with the example $Exp = 29, this condition ...
if($Exp < $NextLevelExp && $Exp >= $LastLevelExp){
... will NEVER be satisfied, and thus $UserLevel will never be set.
In fact, the only way this will not be an infinite loop is if 3 <= $Exp < 7, in which case the condition will be true in the very first loop and $UserLevel = 2.
Maybe you should explain what you're trying to achieve.
Paul 🙂