How to display a menu if the entered value is true and at end of each option

조회 수: 1 (최근 30일)
Adnan Fino
Adnan Fino 2021년 12월 13일
답변: Prince Kumar 2022년 1월 19일
I am using a function to verify an entered value from csv file, so if the entered value is true the program should display a menu. If it is false it will display a message to re-enter a valid value from the csv file. How can I display the menu again after entering a false value then true one? I tried to use a while loop but it seems not working. I also want to display the menu at the end of each option in the menu. Any ideas about how to do so?
  댓글 수: 1
Adnan Fino
Adnan Fino 2021년 12월 14일
data = Customerdata;
CustomerNumber = input('Enter your Number');
if verifyCustomerNumber (CustomerNumber,data)
disp('True')
m = input('choose: 1:Option 1 2:Option2 3:Option3');
switch m
case 1
case 2
case 3
end
else
disp('False')
CustomerNumber = input("Please enter a valid number");
end
function isValid = verifyCustomerNumber(CustomerNumber,data)
isValid = ismember (CustomerNumber, data{:,"CustomerNumber"});
This is part of my code to verify the customer number, just I would like to know to can I display this menu after entering a wrong number then right number and how to display it at the end of each option. Thanks

댓글을 달려면 로그인하십시오.

답변 (1개)

Prince Kumar
Prince Kumar 2022년 1월 19일
Hi,
You can do it using 'while' loop and 'break' statement. Once you have achieved the desired result you can use 'break' statement to get out of the loop.
Here is an example where the code keep asking for a number until the user enter 4 as input(which is the desired result) :
data = 4;
m = input('Enter a number : ');
while true
if m == data
disp('True');
break;
else
disp('False');
m = input('Enter a number : ');
end
end
I hope you find the above example useful.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by