Lecture-20(loops-Recursion)

# Lecture-20(loops-Recursion) - Decision Loops Decision Loops...

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

Decision Loops Decision Loops terminate if a condition is true Single line if statement causes the loop to terminate Since the condition is being tested at the start of the loop - this is also called a pretest loop

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

View Full Document
Decision Loops (Cont’d) Since the test is happening at the end of the loop, this is called a post test loop - exactly equivalent to the pre-test loop A mechanism to update i, otherwise the loop will continue for ever
Counter-Controlled Loop The start and end of the counter and the increments of the counter are all defined in one statement This is where the actual incrementing happens

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

View Full Document
For Loop Notice that the counter gets updated by one increment after the completion of the loop
Exit For Principal 10000 \$ Interest Rate 15.00% Loan Period 15 years 1 11500 2 13225 3 15208.75 4 17490.06 5 20113.57 6 23130.61 7 26600.2 8 30590.22 9 35178.76 10 40455.57 11 46523.9 12 53502.49 13 61527.86 14 70757.04 The principal and interest at the end of the loan period exceeds \$80000 and hence the loop exits before reporting the values corresponding to i = 15

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

View Full Document
DoWhile Loop Initialization of the counter is necessary Counter has to be advanced manually MsgBox "Counter after the loop:" & i
Do Loop While

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

View Full Document
Nested Loops

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

View Full Document

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