lecture_8

lecture_8 - Click to edit Master subtitle style 10/6/09...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
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

This note was uploaded on 03/22/2009 for the course COMP 116 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 19

lecture_8 - Click to edit Master subtitle style 10/6/09...

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

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