MATLAB: How to write properly the ‘else’ part of the code to make it go back in the beginning

if statementloops

disp('Please Choose an Option:') %selection of the program disp('1.Basic Formula of Torque') disp('2.Formula of Torque using Inerta and Acceleration') disp('3.Torque in Gear Motors') disp('4.Comparing torque in Gears') option=input('Enter the Chosen Number: ');
if(option==1) disp('1.Basic Formula of Torque') elseif (option==2) disp('2.Formula of Torque using Inerta and Acceleration') elseif (option==3) disp('3.Torque in Gear Motors') elseif (option==4) disp('4.Comparing torque in Gears') else disp('Wrong Chose of option please try again') option=input('Enter the Chosen Number: '); end

Best Answer

while true
disp('Please Choose an Option:')
option=input('Enter the Chosen Number: ');
if(option==1)
disp('1.Basic Formula of Torque');break
elseif (option==2)
disp('2.Formula of Torque using Inerta and Acceleration');break
elseif (option==3)
disp('3.Torque in Gear Motors');break
elseif (option==4)
disp('4.Comparing torque in Gears');break
else
disp('Wrong Chose of option please try again')
end
end