Problem with preview looping and never returning

I may be going about this all wrong. I am new to Wix, Velo, and Javascript.

I am having trouble with the editor getting hung when I click preview

The javascript code which seems to do it is this

$w.onReady(function () {
let lineNum = 9999; //assuming this will be a global variable

//Begin the main menu
while (lineNum === 9999) {

    create a dropdown with main menu selections
   when dropdown menu makes another selection I set lineNum to a different value 
   depending on the dropdown
   The expectation would be that when I change the lineNum value, I drop out of the 
   while loop

   } //end main menu

when I click preview, preview goes into an infinite loop from which I cannot escape.

Any help is appreciated!

[Which editor or feature is your question most relevant to? e.g. Wix Editor, Wix Studio Editor, Editor X.]

What are you trying to achieve:
[Explain the details of what you are trying to achieve. The more details you provide, the easier it is to understand what you need.]

What have you already tried:
[Share resources, forum topics, articles, or tutorials you’ve already used to try and answer your question.]

Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]