Download presentation
Presentation is loading. Please wait.
Published byNoah Bond Modified over 9 years ago
1
CSC 162 Visual Basic I Programming
2
Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit condition is tested after the body is executed at least once
3
Pretest Loops While/Wend or Do While/Loop Do Until/Loop
4
While/Wend or Do While/Loop While condition body_of_code Wend Do While condition body_of_code Loop As long as the condition remains satisfied, the loop will continue to execute. Once the condition is false, the code will resume execution after the Wend or Loop statement.
5
Example Dim intCounter As Integer Dim intSquare As Integer intCounter = 0 Do While intCounter <= 10 intSquare = intCounter ^ 2 Print intCounter & " squared is " & intSquare intCounter = intCounter + 1 Loop
6
Do Until/Loop Do Until condition body_of_code Loop As long as the condition is not satisfied, the loop will continue to execute. Once the condition is true, the code will resume execution after the Loop statement.
7
Example Dim intCounter As Integer Dim intSquare As Integer intCounter = 0 Do Until intCounter > 10 intSquare = intCounter ^ 2 Print intCounter & " squared is " & intSquare intCounter = intCounter + 1 Loop
8
MsgBox Function intUserChoice = MsgBox("Your average is " & sngAverage, _ vbOkOnly, "Average") MsgBox(Message, Type, Title) The message box is used to display information or to provide the user with a choice. The message box will provide information back to the program about which button the user presses, so it needs to be assigned to an integer variable. Types of message boxes are found in Section 10.11 (pages 438 – 443).
9
Class Discussion Page 125 #4.11 Lab Page 125 #4.16
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.