I am writing a code which the code asks the user for 3 inputs. one should be numeric and other two need to compared using strcmp(). How do i make it to ask for the input again if one of the conditions is false. The user needs to be asked again and again until he puts in the correct inputs

 Accepted Answer

karan - use a while loop to ask for input until some condition is satisfied. For example,
number = 0;
while true
number = input('Please enter a number between 1 and 42: ');
if number >= 1 && number <= 42
break;
end
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!