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

1 次查看(过去 30 天)
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