How to redirect user if they enter an incorrect input
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Mischa Kim
am 2 Dez. 2016
Bearbeitet: Mischa Kim
am 2 Dez. 2016
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!