Stuck in a while loop, want to revert back to previous menu.

Hi Matlab Community, if you see in my code below I would like to display an error message if the incorrect option is chosen in my menu. I would also like it to revert to the choices again after displaying said error message. as it stands everytime I run the script and the error message displays it get stuck in a loop.
I am very new to matlab, so any help is greatly appreciated.
choice = menu('Where are you travelling from?','Mercury','Earth','Jupiter');
if choice == 1;
choice = menu('Where are you travelling to?','Mercury','Earth','Jupiter');
while choice==1
disp('ERROR - You have chosen this planet as your start point, please choose a destination that is different from your start point');
end;

1 Comment

Solved it.
while choice==1
display('ERROR - You have chosen this planet as your start point, please choose a destination that is different from your start point.');
choice = menu('Where are you travelling to?','Mercury','Earth','Jupiter');
end;

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 2 Dec 2016

Edited:

on 2 Dec 2016

Community Treasure Hunt

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

Start Hunting!