Matlab Octave Control Elements

From NovaOrdis Knowledge Base
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;

Conditions

Equality