{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter4-1e - forLoops whileLoops(next forloop for =...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Iteration Control Structure “for” Loops “while” Loops (next)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
      Typical Code Structure  “for” loop for <var> = <loop_list> statement 1 statement 2 : : statement n end Note indentation for easier reading
Background image of page 2
      Typical Code Structure  “for” loop for index = 1:0.5:25 y = 3 * index statement 2 : index = 3 * y : statement n end Note loop index may be  used in assignment  statements, etc., as any  normal variable Note loop index should not be  reassigned during loop. Loop index need not be  incremented by “1”. Any array  may be used. If empty, loop is  NOT executed. This is NOT an  assignment statement.  There is NO named  array named “index”.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
      2 Unique Loop Statements for index = 1:100 statement 1 statement 2 : continue break : statement n end statement Immediately terminates  loop being executed.  Continues at next  statement after “end” Immediately advances  to next loop index.  Loop continues  normally.       Effective in “while” loops as well
Background image of page 4
% Class Example 4_1 - "For" Loops % EGR 115 - Prof Newman % clear disp('Testing the "FOR" loop structure.') % initialize counter and accumulator count = 0; total = 0; for index = 1:1:100     count = count + 1;    % increment counter
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}