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

 채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 23일

0 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2020년 4월 23일

답변:

2020년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by