简体   繁体   English

循环时如何继续?

[英]How can i continue while cycle?

The user is typing his/her password until it would be correct.用户正在输入他/她的密码,直到密码正确为止。 When user want to click "Cancel" we ask "Are you sure?"当用户想要单击“取消”时,我们会询问“您确定吗?” and if the answer is no, then again ask for the password.如果答案是否定的,则再次询问密码。

I tried to use to strat again but it does not work =(我尝试再次使用Strat,但它不起作用=(


var password = "username",
    user_password        ,
    checked = true       ,
    user_password = prompt("Enter your password"),
    checked_confirm      ;

label: while(checked){
    if(user_password == password){
        alert("You are successfully logged in");
        break;
    }
    else if(user_password == null){
        checked_confirm =  confirm("Are you sure you want to cancel authorization?");
        if(checked_confirm){
            alert("You have canceled authorization");
            break;
        }
        else{
            continue lable;
        }
    }
    else{
        user_password = prompt("Enter your password");
    }
}

Ask for the password at the start of the loop, and don't break `till you get it:在循环开始时询问密码,在你得到密码之前不要中断:

 var password = "username", user_password, checked_confirm; while (true) { user_password = prompt("Enter your password"); if (user_password == password) { alert("You are successfully logged in"); break; } else if (user_password == null) { checked_confirm = confirm("Are you sure you want to cancel authorization?"); if (checked_confirm) { alert("You have canceled authorization"); break; } } else { alert("Wrong password"); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使我的SlickJS Carousal在3张图像之间循环,并在循环时将它们全部可见? - How can I get my SlickJS Carousal to cycle between 3 images and have them all visible while cycling? iPhone / Safari:如何在睡眠模式下继续执行javascript? - iPhone/Safari: How can I continue to execute javascript while in sleep mode? 如何在Javascript中循环4个变量的值? - How can I cycle the values of 4 variables in Javascript? 如何在错误后停止循环“FOR” - How can I stop cycle “FOR” after mistake 如何在同一选项卡中继续? - How can I continue in same tab? 如何停止ajax请求然后继续? - How can i stop ajax request and then continue? 我最近开始学习 Graphs 中的周期检测。 如何使用下面的代码检测循环? 代码显示没有循环,但有一个循环 - I recently started learning cycles detection in Graphs. How can I detect the cycle with the code below? The code show no cycle but there is a cycle 如何等待直到异步功能完成,然后继续循环? - How to wait until the async function is done and then continue the cycle? 单击时,如何在AngularJS中逐个循环JSON - On click How can I cycle through JSON one by one in AngularJS 如何在事件中一次一个地循环元素列表? - How can I cycle through a list of elements one at a time on an event?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM