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

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by