Lecture 5 - 10/4/2010 Lecture 5: For loops BMEn 2401...

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

View Full Document Right Arrow Icon
10/4/2010 1 Lecture 5: For loops BMEn 2401 Programming for Biomedical Engineers Rich Beck September 7, 2010 Today’s Lecture rand function for loop More on array addressing 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
10/4/2010 2 Flow Control if-end , if-else-end , and if- elseif-else-end statements while-end loop for-end loop switch-end statement Each Flow Control statement or loop requires an accompanying “ end ” - it cannot share an end ” ; it must have its own. 3 Review: if-elseif-else-end What is the difference between the following statements: if x < 0 f_x = -x^2; elseif x == 0 f_x = 0 ; else f_x = x^2; end if x < 0 f_x = -x^2; end if x == 0 f_x = 0 ; end if x > 0 f_x = x^2; end 4
Background image of page 2
3 rand function The function rand creates a single random number between 0 and 1. Example: a = rand a = 0.9501 5 Test yourself heads = 0; tails = 0; total_tosses = 0; while total_tosses <= 100 tossing_result = rand ; if tossing_result < 0.5 heads = heads + 1; else tails = tails + 1; end total_tosses = total_tosses + 1; end See the remaining of the program on the next slide. 6
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Lecture 5 - 10/4/2010 Lecture 5: For loops BMEn 2401...

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

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