{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_8

# lecture_8 - Click to edit Master subtitle style Lecture 8...

This preview shows pages 1–11. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style 10/6/09 Lecture 8 Comp 116 Feb 4th , 2009 10/6/09 Objectives Branching, loops 10/6/09 Branching 10/6/09 Coin tosses Do something if number of heads is 1 2 3 … 10/6/09 The switch statement switch ( expression ) case value1 commands; case value2 commands; case value3 commands; otherwise commands ; end; 10/6/09 Loops 10/6/09 Repetitive Execution For loop syntax Do something a set number of times var assigned to each value/element within rowvec var: loop index variable for var = rowvec commands; end; 10/6/09 For Loops Example What does this do? prod = 1; for i = 1:10 prod = prod * i; end; 10/6/09 Example Number guessing example 10/6/09 For Loops Repeat code a number of times Do something with the numbers in a vector Index into some elements of a vector for i = 1:10 fprintf('Matlab is fun\n'); end; for i = 2:2:10 fprintf('%d is even\n', i); end; for i = 1:10 fprintf('x(%d) is %0.2f\n', i, x(i)); end; 10/6/09...
View Full Document

{[ snackBarMessage ]}

### Page1 / 19

lecture_8 - Click to edit Master subtitle style Lecture 8...

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

View Full Document
Ask a homework question - tutors are online