MATLAB: Re running the code

errorerror handlingiterationloopsMATLAB

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

Best 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
Related Question