Lecture-20(loops-Recursion)

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

Info iconThis preview shows pages 1–6. 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
Background image of page 1

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

View Full DocumentRight 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
Background 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
Background image of page 3

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

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

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online