簡體   English   中英

循環時如何繼續?

[英]How can i continue while cycle?

用戶正在輸入他/她的密碼,直到密碼正確為止。 當用戶想要單擊“取消”時,我們會詢問“您確定嗎?” 如果答案是否定的,則再次詢問密碼。

我嘗試再次使用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");
    }
}

在循環開始時詢問密碼,在你得到密碼之前不要中斷:

 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM