Download presentation
Presentation is loading. Please wait.
1
Introduction to Computing Dr. Nadeem A Khan
2
Lecture 22
3
Loop structure: General Format ► Do While condition statementsLoop
4
Flow chart: loop structure No Process Step(s) Is condition true ? Yes
5
► Example 1: Sub Command1_Click ( ) Dim num As Integer Let num=1 Do While num<=10 Picture1.Print num; Let num=num+1 Loop End Sub Do Loops
6
► The result: 1 2 3 4 5 6 7 8 9 10 Do Loops
7
► Example 2: Sub Command1_Click ( ) Dim passWord as String, info As String If Ucase(Text1.Text) = “SECRET.TXT” Then Let passWord=“” Do While passWord <> “SHAHID” Let passWord = InputBox$(“Enter passWord”) Let passWord = Ucase(passWord) Loop End If ‘ Remaining statements on next slide Do Loops (Contd.)
8
► Example 2 (Contd.): ‘Continues from the previous slide Open Text1.Text For Input As #1 Input #1, info Picture1.Print info Close #1 End Sub Do Loops (Contd.)
9
Do-Loop-Until: General Format ► Do statements Loop Until condition Flow chart?
10
Do-Loop-Until: General Format ► Modify example 2 to Do-loop-Until Format
11
► Example 1: Sub Command1_Click ( ) Dim passWord as String, info As String If Ucase(Text1.Text) = “SECRET.TXT” Then Do Let passWord = InputBox$(“Enter passWord”) Let passWord = Ucase(passWord) Loop Until passWord = “SHAHID” End If ‘ Remaining statements on next slide Do-Loop-Until (Contd.)
12
► Example 1 (Contd.): ‘Continues from the previous slide Open Text1.Text For Input As #1 Input #1, info Picture1.Print info Close #1 End Sub Do-Loop-Until (Contd.)
13
Do-Loop: Another Example ► When will the following program come to its end?
14
Do-Loop: Another Example Sub Command1_Click ( ) Dim num As Single num = 7 Do While num <> 0 num=num-2Loop End Sub
15
Note: ► Read: Schneider (Section 6.1) ► Read comments and do practice problems of these sections of these sections ► Attempt some questions of Exercises
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.