Post on 18-Jan-2018
description
transcript
Clearly Visual Basic: Programming with Visual Basic 2008
Chapter 14 Do It, Then Ask Permission
Clearly Visual Basic: Programming with Visual Basic 2008
Objectives
• Write a posttest loop using the Do…Loop statement• Show a posttest loop in both pseudocode and a
flowchart• Concatenate strings
2
Clearly Visual Basic: Programming with Visual Basic 2008
Testing after the Fact
• Instructions in a pretest loop – May never be processed
• Instructions in a posttest loop – Will be processed at least once
• Figure 14-1 – Shows the problem specification and algorithms
3
Clearly Visual Basic: Programming with Visual Basic 2008 4
Clearly Visual Basic: Programming with Visual Basic 2008 5
Clearly Visual Basic: Programming with Visual Basic 2008 6
Clearly Visual Basic: Programming with Visual Basic 2008 7
Clearly Visual Basic: Programming with Visual Basic 2008 8
More on the Do … Loop Statement
• Pretest syntax– The {While | Until} condition section
• Part of the Do clause • Indicates that the condition is evaluated before the
loop instructions are processed
• Posttest syntax– The {While | Until} condition section
• Part of the Loop clause• Indicates that the condition is evaluated after the loop
instructions are processed
Clearly Visual Basic: Programming with Visual Basic 2008 9
Pseudocode and Flowchart for a Posttest Loop
• Figure 14-4 – Shows the pseudocode and flowchart for Example 2
in Figure 14-3• The repetition diamond
– Appears at the bottom of the loop in a posttest loop
Clearly Visual Basic: Programming with Visual Basic 2008 10
Clearly Visual Basic: Programming with Visual Basic 2008
11
The Good Morning Application
• Figure 14-5– Shows the interface for the Good Morning application
• Figure 14-6– Shows each message on a separate line in the
control• Figure 14-7
– Shows the pretest and posttest loops in the Good Morning application
– Describes the way the computer processes the code in each loop when the user enters the number 0
Clearly Visual Basic: Programming with Visual Basic 2008 12
Clearly Visual Basic: Programming with Visual Basic 2008 13
Clearly Visual Basic: Programming with Visual Basic 2008 14
Clearly Visual Basic: Programming with Visual Basic 2008 15
Clearly Visual Basic: Programming with Visual Basic 2008 16
But They Said There Were No Strings Attached
• Concatenation operator– The ampersand (&)– Used to concatenate (connect or link) strings
together• ControlChars.NewLine constant
– Represents the Enter key on your keyboard – Used to create a new line
Clearly Visual Basic: Programming with Visual Basic 2008 17
Clearly Visual Basic: Programming with Visual Basic 2008 18
Summary
• Instructions in a posttest loop – Will be processed at least once
• Do…Loop statement – Used to code a posttest loop
• To concatenate strings – Use the concatenation operator: ampersand (&)
• Enter key – Represented by the ControlChars.NewLine
constant
Clearly Visual Basic: Programming with Visual Basic 2008 19