Clearly Visual Basic Programming with Visual Basic 2010
Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition Chapter 13 Do It, Then Ask Permission (Posttest Loops)
Objectives After studying Chapter 13, you should be able to: Show a posttest loop in both pseudocode and a flowchart Write a posttest loop using the Do…Loop statement 2 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Testing After the Fact Posttest loop Condition evaluated after loop instructions are processed Instructions in a pretest loop May never be processed Instructions in a posttest loop Will be processed at least once Figure 13 -1 Shows the problem specification and algorithms 3 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Figure 13 -1 Rob algorithms containing pretest and posttest loops 4 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Figure 13 -2 Selection structure added to Algorithm 2 from Figure 13 -1 5 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
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 6 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Figure 13 -3 Syntax and examples of the Do…Loop statement for a posttest loop 7 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Pseudocode and Flowchart Containing a Posttest Loop Figure 13 -4 Shows the pseudocode and flowchart for Example 2 in Figure 13 -3 The condition represented by the diamond Appears at the bottom of the loop in a posttest loop 8 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Figure 13 -4 Pseudocode and flowchart for Example 2 in Figure 13 -3 9 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
The Bouncing Robot Application This application bounces a robot up and down on the form Number of bounces is entered in a text box • Code and test the Bouncing Robot application Follow instructions on pages 235 -236 Then modify the Posttest Loop button’s code Follow instructions on page 236 10 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Figure 13 -5 Selection structure added to the btn. Posttest control’s Click event procedure 11 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
Summary Instructions in a posttest loop Will be processed at least once Do…Loop statement Used to code a posttest loop in Visual Basic Condition can be phrased as either a looping condition or a loop exit condition Loop clause contains either: While keyword Until keyword 12 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition
- Slides: 12