How to keep iterating through loops in MATLAB -


i have matlab code

usrinput = input('enter month: ', 's'); if strcmp(usrinput, 'july')     disp('summer') elseif strcmp(usrinput, 'january')       disp('winter') elseif strcmp(usrinput,'october') disp('fall') elseif strcmp(usrinput, 'april') disp('spring') end 

where input month , gives season, every time call script (called month) , input month in have call script again month. how can set don't have call script every time. aka after type in july , says winter, automatically "enter month:" again , can type in new month thanks!

you can use infinite "while loop" using while(1), can have more elegant code using switch, here code:

while (1)     usrinput = input('enter month: ', 's');     switch usrinput         case 'july'             disp('summer')         case 'january'             disp('winter')         case 'october'             disp('fall')         case 'april'             disp('spring')         case 'exit'             break         otherwise             disp('please enter month.')     end end 

the loop running until user type 'exit'.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -