Matlab Octave Control Elements

From NovaOrdis Knowledge Base
Revision as of 23:30, 6 January 2018 by Ovidiu (talk | contribs) (→‎Internal)
Jump to navigation Jump to search

Internal

Loops

For all loops, 'break' and 'continue' work:

for

for i = <range> <statement> end;
for i = 1:10 disp(i) end;

The range can be a vector:

v = [2 4 6 8]
for i = v disp(i) end;

while

i = 1;
while i <= 5; i = i + 1; end;

if

if <condition> 
    <statement> 
endif;
if <condition> 
    <statement> 
else 
    <statement> 
endif;
if <condition> 
    <statement> 
elseif <condition>
    <statement> 
...
else 
     <statement> 
endif;