How to redirect user if they enter an incorrect input

조회 수: 11 (최근 30일)
Bree
Bree 2016년 12월 2일
편집: Mischa Kim 2016년 12월 2일
In my program, I prompt the user for an input of a string. If they enter an incorrect input, my program displays the message "Error. Please enter one of the options.". However, my program stops there and doesn't ask for the input again. What would I use to redirect the user back to the input? Thank you.

답변 (1개)

Mischa Kim
Mischa Kim 2016년 12월 2일
편집: Mischa Kim 2016년 12월 2일
Bree, without knowing the structure of your program I would suggest using a while -loop.
Put the prompting commmand into the loop and set a flag that causes the loop to be excited once the input is "correct".
FLAG = false;
while ~FLAG
% the input prompt would go here
if *input is correct* % replace accordingly
FLAG = true;
end
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by