MATLAB: Problem with code originally written for MATLAB R2006a — problems with break statement

breakloopsMATLABr2006a

Hi all,
I'm currently running a program with code that was originally written for MATLAB R2006a or R2007b for a research project, but I only have access to R2019b (through university computer access). There is an issue that seems to be due to a change in syntax from past versions, and I'm wondering if anyone has any insight to this issue.
The line of code that I am running into problems is:
if A==0;break;end
This returns an error statement of: '"BREAK can only be used in a FOR or WHILE loop"
I know there isn't a lot of detail in my problem, but I am relatively new to Matlab. Is there a way that this can be fixed? Any insight is greatly appreciated!

Best Answer

Long ago, no error message was generated for a break outside of any loop. I never used that behavior myself... I think I encountered it exactly once myself (in a situation where return was appropriate instead in that one case.)
I have read about it a very small number of times, and my memory is telling me that in the very small number of cases I saw, that the break could be commented out, as the logic was broken in the routines anyhow and failing to change flow of control did not make a substantial difference. Things like reading from the wrong directory, code that never worked properly, so commenting out the break just removed the syntax distraction to allow people to run the code and experience for themselves that the routine was rot.