Lecture 5

# Lecture 5 - Lecture 5 For loops BMEn 2401 Programming for...

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

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

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

View Full Document
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
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

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.

## This note was uploaded on 11/10/2011 for the course BMEN 2051 taught by Professor S during the Fall '10 term at Minnesota.

### Page1 / 14

Lecture 5 - Lecture 5 For loops BMEn 2401 Programming for...

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

View Full Document
Ask a homework question - tutors are online