Lecture-20(loops-Recursion)

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
For Loop Notice that the counter gets updated by one increment after the completion of the loop
Image of page 4
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
Image of page 5

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

View Full Document Right Arrow Icon
DoWhile Loop Initialization of the counter is necessary Counter has to be advanced manually MsgBox "Counter after the loop:" & i
Image of page 6
Do Loop While
Image of page 7

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

View Full Document Right Arrow Icon
Nested Loops
Image of page 8
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern