Remove all other code than what you’re specifically looking at so that there’s less going on.
A while-loop continues for as long as the condition is met. What variables are used in the condition, what values do they have? That’s something you can print out and look at.
To post code on a forum you’ll need to tell the forum not to apply regular text formatting rules, to leave it alone. There are a couple of buttons in the editor, one of them is for that.
It looks a bit as if though you’ve got while-else in your code. What does that do? I expect you don’t know, but you should be aware of that you don’t know that - because you can’t possibly leverage it if you don’t know what it does. You need to be super deliberate about everything you write.