Lecture-20(loops-Recursion)

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

This preview shows pages 1–6. 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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/27/2008 for the course PGE 310f taught by Professor Srinivasan during the Spring '08 term at University of Texas.

### 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
Ask a homework question - tutors are online