simple example.

var ask = prompt("enter your login"); while (ask != "Admin") { ask = prompt("enter your login"); console.log(ask != "Admin"); // true }; if (ask == "Admin") { alert("Hello, Admin"); } 

I deliberately enter not "Admin" enters the cycle 1 time and if you enter not "Admin", leaves the cycle, although it should loop, until you enter "Admin"

  • one
    The problem you described is not reproduced. - Nick Volynkin
  • one
    Why not use the do ... while loop? - Oleg

2 answers 2

And so?

 var ask = prompt("enter your login"); while(ask != "Admin") { ask = prompt("enter your login"); console.log(ask != "Admin"); // true } if (ask == "Admin") { alert("Hello, Admin"); } 

  • one
    And what is the difference? - Pavel Mayorov
  • In the absence of a semicolon after while :). - Igor

Still, you can use another cycle:

 var ask; do { ask = prompt("enter your login") } while (ask != 'Admin') 

You can still like this:

 while (true) { var ask = prompt("enter your login"); if (ask == "Admin") { alert("Hello, Admin"); break; } else { console.log(ask != "Admin"); } }; 

Please note that Admin and admin will be two different usernames.