17
Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Embed Size (px)

Citation preview

Page 1: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Chapter 15 I’m on the Inside; You’re on the

Outside (Nested Loops)

Clearly Visual Basic: Programming with Visual Basic 2010

2nd Edition

Page 2: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Objectives

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition2

After studying Chapter 15, you should be able to:Nest repetition structuresUtilize a text box’s Multiline, ReadOnly, and ScrollBars properties

Page 3: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

One Loop within Another Loop

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition3

Repetition structures can be nestedProgrammer

Determines whether a problem’s solution requires a nested repetition structure

Figure 15-1 Shows problem specification and algorithm

from Chapter 12

Page 4: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition4

Figure 15-1 Problem specification and algorithm for signing one book for each customer

Page 5: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition5

Figure 15-2 Problem specification and algorithm for signing zero or more books for each customer

Page 6: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clock Application

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition6

Clock Uses nested repetition structures to keep

track of timeThe second hand is controlled by the inner

(nested) loopThe minute hand is controlled by the outer

loopFigure 15-3 shows logic used by clock’s

minute and second handsFigure 15-4 shows interface for the Clock

application

Page 7: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition7

Figure 15-3 Logic used by a clock’s minute and second hands

Page 8: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition8

Figure 15-4 Clock application’s user interface

Page 9: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Revisiting the Monthly Payment Calculator Application

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition9

Figure 15-6 Shows the output, processing, input items,

and algorithm for the Monthly Payment Calculator application

Application calculates and displays: Monthly payments on a loan

Payments are calculated using: Principal and term entered by the userA loop that varies the annual interest rates from 4%

through 7%

Page 10: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition10

Figure 15-6 Planning information for the Monthly Payment Calculator application from Chapter 14

Page 11: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition11

Figure 15-7 Planning information for the modified Monthly Payment Calculator application

Page 12: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Revisiting the Monthly Payment Calculator Application (cont’d.)

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition12

ScrollBars property Indicates whether any scroll bars appear on

the text boxMultiline property

Specifies whether the text box can accept and display multiple lines of text

Setting the text box’s ReadOnly property to TruePrevents user from editing contents of a text

box

Page 13: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition13

Figure 15-11 Click event procedure for the btnCalc control

Page 14: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

But I Want To Do It a Different Way

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition14

Use two Do…Loop statements or one For…Next statement and one Do…Loop statement

Page 15: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition15

Figure 15-12 Modified Click event procedure for the btnCalc control

Page 16: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Summary

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition16

Repetition structures can be nestedFor a nested repetition structure to work

correctly:It must be contained entirely within the outer

repetition structureWhen a text box’s Multiline property is set

to True:It can accept and display multiple lines of

text

Page 17: Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

Summary (cont’d.)

Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition17

A text box’s ScrollBars property Determines whether scroll bars appear on

the controlSetting the text box’s ReadOnly property to

TruePrevents the user from editing contents of a

text box