{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture8

# Lecture8 - EGR 106 Lecture 8 Loops Break Continue Commands...

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

EGR 106 Lecture 8 Loops, Break, Continue Commands “for-end” loops “while-end” loops Nested loops “break” and “continue” commands Textbook: 6.4 – 6.6

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

View Full Document
Loops Commands to repeatedly execute certain blocks of code Two common types in MATLAB: for while
The “for-end” Loop

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

View Full Document
Example – Sum the series + + + + + = ! 4 1 ! 3 1 ! 2 1 ! 1 1 1 e sum=1; for n=1:10 sum=sum+(1/factorial(n)); fprintf('\nsum = %5.4f',sum) end sum = 2.0000 sum = 2.5000 sum = 2.6667 sum = 2.7083 sum = 2.7167 sum = 2.7181 sum = 2.7183 sum = 2.7183 sum = 2.7183 sum = 2.7183 Important – Must First Initialize Value
Example – calculating interest for 10 years: Note the use of num2str

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

View Full Document
Example – implement a count down timer (in seconds):

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

View Full Document
The “while-end” Loop while conditional expression . . . . . . . . . end Group of MATLAB commands Conditional expression must include at least one variable which is assigned and changed as the Group of MATLAB commands are executed - code is started for the case with conditional statement true - group of MATLAB commands are executed and conditional statement is rechecked

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.

{[ snackBarMessage ]}

### Page1 / 25

Lecture8 - EGR 106 Lecture 8 Loops Break Continue Commands...

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

View Full Document
Ask a homework question - tutors are online