你可以把你迭代循环内的计数器:
locked_flag = false
counter = 0
while (x ~= 1111)
if (x == password)
uiwait(msgbox('Welcome!'));
break;
else
uiwait(errordlg('Try Again!!'));
counter = counter + 1
if (counter == 3)
locked_flag = true;
%show 'locked' dialog of some kind here
break;
end
X = inputdlg('Please enter your password');
x = str2double (X{1,1});
end
end
%can now check if locked_flag true to start unlock logic or other...
编辑:是的,我只希望你张贴代码片段,你需要它上面的逻辑,这样,如果对不起不清楚:
X = inputdlg ('Please enter your password');
x = str2double (X {1,1});
password = 1111; %whatever
if (x == password)
uiwait(msgbox('Welcome!'));
else
locked_flag = false
counter = 1
while (x ~= 1111)
if (x == password)
uiwait(msgbox('Welcome!'));
break;
else
uiwait(errordlg('Try Again!!'));
counter = counter + 1
if (counter == 3)
locked_flag = true;
%show 'locked' dialog of some kind here
break;
end
X = inputdlg('Please enter your password');
x = str2double (X{1,1});
end
end
end
%can now check if locked_flag true to start unlock logic or other...
你是相当接近,而不是在而L使用'x' oop,使用一个变量来计数。初始化如下'failed_count = 0',然后运行'while(failed_count