Chances are if you follow good software engineering principles, clean, modular, properly indented code, then the extra layer of protection added by writing
#Octave for loop code#
Especially given the state of most academic code out there, which is usually a bunch of unindented spaghetti code with lots of nestedīlocks that goes on for miles in a single file. And, at the very least, they provide a very strong visual signposting of where you are in the code (did I just close that for loop, or did I just exit an if block). There are many other situations where endifs and endfors would protect you when simple Octave will immediately warn you that something is awfully wrong, and it will stop you from shooting yourself on the foot. However, I feel a need to play devil's advocate here, because it makes it sound like the octave developer's decision to provide these keywords was misguided, when actually there is good reason, and knowing the benefits of using endfor, endif allows you to make an informed decision on when and why to avoid them.Īllow me to demonstrate their usefulness with an example:ĭisp('do some very important thing here that absolutely must be done always')Ĭan you spot the subtle but deadly bug here? In practice I mostly agree with Cris' answer, and I follow the same advice in principle.
Below are the various basic functionalities of Octave : it is free to use, whereas MATLAB is not thus MATLAB requires a license to operate. It can also be used to implement various machine learning algorithms with ease. What is octave used for in machine learning?.
See octave manual: The-for-Statement But keep in mind that for loops are slow in octave so it may be desirable to use a vectorized method. If you use for i = z when z is a matrix, then i takes the value of the first column of z (6.1101 5.5277 8.5186), then the second column and so on. Many functions can use a matrix input for most common calculations.