Lecture 2-18-08

# Lecture 2-18-08 - Matthew Bessette ENGR 141-107 Looping...

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

Matthew Bessette ENGR 141-107 February 18, 2008 Looping Structures: “for” Loops - Why do we need looping? o Repetition of a code segment o Recall the algorithm for calculating a factorial o Soil homework – “repeat unless organic” - Definite Loops – For Loops o A segment of code executes a certain number of times o Ex: counting, data processing, sampling - Indefinite Loops – While loops o Also referred to as conditional loops o A segment of code repeated executes until a certain condition is satisfied o Any for-loop can also be written as a while loops o Ex: validating input, calculations - Definite Loops: For loops o Execute a certain number of times o Sampling rate o Counting backwards o Palm p.211 for counter=start:step:finish %executable statements (may use counter) % it is bad practice to change loops index numbers % counter = 2 (causes code to never finish infinite loop) % counter=counter-3 End - Where to Use? o Inside Programs o Inside Functions - Definite Loops o We can display the numbers 1 10 as follows: for M = 1:1:10 disp(M) end o What if we want to display 10 1 for w=10:-1:1

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 ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern