Jump command in MATLAB

瘦欲@ 提交于 2019-11-27 16:02:35

There is no goto statement in MATLAB, but there are a few other commands for use with loops that may help you:

  • continue: This statement will skip the remaining commands in a for or while loop and move on to the next iteration.
  • break: This statement will terminate execution of a for or while loop.

There is no goto in matlab. However, this does not say you cannot structure your code to use an {if, else, elseif, end} structural form for your code. Or use a {switch, case, end} form. Or call a function (or subfunction or nested function) to solve your problem. Or use a continue/break to structure your code. One can always solve these problems using one of the existing forms of flow control available.

The use of functions can improve your code in other ways, often by making it more modular, and therefore easier to debug and write.

that solves the problem easily:

caseno = input('input your case no');

switch (caseno)
     case 1
          disp('this first section will run');
     case 2
          disp('this second section will run');
     otherwise
          disp('wrong case no');
end
Prince Rajput
for j = 1: 1: 24
  % LABEL start
a = a + j;
if a > 10
goto('start') % If condition satisfied goto label start
return
else
  a = a + 1;
end
end
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!