Write a program that answers the question "stop the program?", Asks for the answer "yes", the program should stop only if the user enters "yes". /*Thank you in advance
Closed due to the fact that off-topic participants Qwertiy ♦ , user31688, Athari , aleksandr barakin , VladD Jun 10 '15 at 19:13 .
- Most likely, this question does not correspond to the subject of Stack Overflow in Russian, according to the rules described in the certificate .
- fourI vote for the closure of this issue as not relevant topic, because the author did not even try to do something. - Qwertiy ♦
|
2 answers
With a do / while loop, this trick will not work. It is executed synchronously and the process just hangs on an infinite loop.
Another option to do something similar is to use the interval. For example: http://jsfiddle.net/IonDen/f5xmrb7d/
var $stop = $("#stop"), $debug = $("#debug"), flag = true, i = 0; $stop.on("click", function () { var conf = window.confirm("Stop the program?"); if (conf) { flag = false; } }); var inter = setInterval(function () { i++; $debug.html(i); if (!flag) { clearInterval(inter); } }, 50);
|
Where is your code?
Make it easy:
var answer = null, i = 0; do{ console.info("Итерация №" + i); i++; answer = prompt("Остановить программу?"); if(answer == null) // Fix to "No" button answer = ""; }while(answer.toLowerCase() !== 'да');
|