For+While+posted

For+While+posted - for loops Execute collection of...

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

View Full Document Right Arrow Icon
for loops Execute collection of statements a fixed number of times. for x = array statements end Execution continues with any statements beyond the end The statements are executed one time for each column in the array . In the code above, x is the loopvariable Before each “execution pass,” the loopvariable x is assigned to the corresponding column of array. 1 st column on first pass, 2 nd column on second pass, and so on
Background image of page 1

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

View Full DocumentRight Arrow Icon
for loops, most common use(!) The most common value for array is a row vector of integers, starting at 1 , and increasing to a limit n for x = 1:n statements end The array is simply the row vector [ 1 2 3 4 n ] Hence, the statements are executed n times. The first time through, the value of x is set equal to 1 ; the k ’th time through, the value of x is set equal to k . array
Background image of page 2
for loops, most common use for x = 1:n statements end is the same as array = 1:n; for x = array statements end The array can be created before the loop itself, so
Background image of page 3

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

View Full DocumentRight Arrow Icon
for loops, examples
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/14/2010 for the course E 7 taught by Professor Patzek during the Summer '08 term at Berkeley.

Page1 / 16

For+While+posted - for loops Execute collection of...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online