Statements That Repeat
For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if less than end. If so, repeat loop again. If not, go to statement after Next.
Do While...Loop Structure Do While condition statements Loop Where The condition is tested, and if true the loop is repeated. When the condition is false, the loop statements are skipped the statement after Loop is executed.
Do Until...Loop Structure Do Until condition statements Loop Where The condition is tested, and if false the loop is repeated. When the condition is true, the loop statements are skipped the statement after Loop is executed.
‘Calculate the factorial of a number given by user Dim Factorial As Double Dim I As Integer I = 1 Factorial = 1 Do While I <= Val (txtAnswer.text) Factorial = Factorial + 1 I = I + 1 Loop Do Until...Loop Structure User gives number
Loops with the Marching Band Project Hands-On Exercise 3 (P ) –Create the Marching Band Project –Add Command Buttons and a Timer –Add Controls to Display the Band –Add Banner Comments –Add Code for Buttons and the Form –Add Code to Add Animation –Run, Save, Test and Debug Your Project –Create a Copy of the Project –Change Animation Code –Update, Run, Save, Test and Debug –Exit Visual Basic
Summary... Fundamental programming demonstrated Variables vs. Constants Data types Local vs Global variables Functions and Procedures Control structures: sequence, selection and repetition
Summary Statements –Dim, Static, Const –Public, Private –Sub, Function –Do...Loop, Do While...Loop, Do Until...Loop –For Each...Next, For...Next –If...Then...Else –Select Case
Practice with Visual Basic 1. Learning to Subtract Game (P.148) 2. Wind Chill in Celsius (P.148) 3. Heat Index (P.148) 4. Rock, Paper, Scissors Game(P.150)
Case Studies Calculate a Formula Weather Calculations More Fun and Games More Web Resources for Visual Basic
End of Lecture