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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -