let i = 1;

while (i <= 5) {
    console.log(i);
    i++;
}
// Output: 1 2 3 4 5
while (condition) {
    // Code block to execute
}
<button id="btn" type="button">Enter Your Name</button>

<script>
    const btn = document.getElementById("btn");

    /* Register an event so that the user can click the button
       and enter a name in the prompt */
    btn.addEventListener("click", function() {
        let userName = null;

        while (!userName) { // Continue executing prompt while userName is a falsy value
            /*
             * Returns the entered string when text is entered in the prompt and
               the OK button is clicked
             * Returns an empty string ("") when the OK button is clicked without
               entering anything
             * Returns null when the Cancel button is clicked
            */
            
            // Assign the return value of prompt to userName
            userName = prompt("Please enter your name.");

            /*
             * If prompt returns the entered string
               (when text is entered and the OK button is clicked),
             * change the button text
             * and disable the button using the disabled attribute
            */
            if (userName) {
                this.textContent = "Nice to meet you, " + userName + "!";
                this.setAttribute("disabled", "");
            }
        }
    });
</script>
Rendered Output Click the 'Enter Your Name' button to execute the example code above.
If you do not enter a name in the prompt, the prompt continues to appear.
let i = 1;

while (i <= 5) {
    console.log(i);
    /* Without the increment/decrement expression in this code, an infinite loop occurs. */
    // i++;
}