Introduction to Computing Dr. Nadeem A Khan. Lecture 22.

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

Looping Structures: Do Loops
CS 4 Intro to Programming using Visual Basic Do Loops Patchrawat Uthaisombut University of Pittsburgh 1 based on lecture notes by D. Schneider.
True BASIC Ch. 9 Practice Questions. What are the 4 errors? DIM arr(4) FOR X = 1 TO 4 READ arr(X) LET arr(X) = arr(X) * X PRINT What is the new Y INPUT.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Introduction to Computing Dr. Nadeem A Khan. Lecture 10.
Introduction to Computing Dr. Nadeem A Khan. Lecture 23.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Introduction to Computing Dr. Nadeem A Khan. Lecture 10.
Introduction to Computing Dr. Nadeem A Khan. Lecture 27.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Arrays Chapter 7 Why use arrays? To store & represent lists of homogeneous values To simplify program code To eliminate the need to reread.
Introduction to Computing Dr. Nadeem A Khan. Lecture
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Introduction to Computing Dr. Nadeem A Khan. Lecture 17.
Introduction to Computing Dr. Nadeem A Khan. Lecture 19.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
BACS 287 Programming Fundamentals 4. BACS 287 Programming Fundamentals This lecture introduces the following iteration control structure topics: – Do.
Introduction to Computing Dr. Nadeem A Khan. Lecture 14.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
Introduction to Computing Dr. Nadeem A Khan. Lecture 28.
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Introduction to Computing Dr. Nadeem A Khan. Lecture 18.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
Introduction to Computing Dr. Nadeem A Khan. Lecture 5.
For…Next : Nested Loop X= 0 For i = 0 To 4 For j = 0 To i-1 X=X+(i+j-1) Next j Next i How many times the inner loop is executed? What is x at the end of.
PROGRAMMING In Lesson 5. RECAP  Complete the starter activity.
110-K1 Iterations (1) Up to now, need to call the procedure again (e.g. click again on a command button) To repeat a piece of code: Can also use loops:
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
ENGR 112 Decision Structures.
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Chapter 71 Repetition - Do Loops n A Loops, is used to repeat a sequence of statements a number of time n There are two loops commands in Visual Basic.
Basic problem solving CSC 111.
Count and add list of numbers From user input and from file.
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
Repetition Structures
CS 100 Introduction to Computing Seminar October 7, 2015.
CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.
Introduction to Computing Dr. Nadeem A Khan. Lecture 2.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Controlling Program Flow with Looping Structures
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Chapter 6 Controlling Program Flow with Looping Structures.
Chapter 5 - VB 2008 by Schneider1 Chapter 5 – Repetition 5.1 Do Loops 5.2 Processing Lists of Data with Do Loops 5.3 For...Next Loops.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Introduction to Computing
CSC115 Introduction to Computer Programming
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Case & Repetitive Statements
Repetition - Counting and Accumulating
Presentation transcript:

Introduction to Computing Dr. Nadeem A Khan

Lecture 22

Loop structure: General Format ► Do While condition statementsLoop

Flow chart: loop structure No Process Step(s) Is condition true ? Yes

► 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

► The result: Do Loops

► 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.)

► 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.)

Do-Loop-Until: General Format ► Do statements Loop Until condition Flow chart?

Do-Loop-Until: General Format ► Modify example 2 to Do-loop-Until Format

► 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.)

► 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.)

Do-Loop: Another Example ► When will the following program come to its end?

Do-Loop: Another Example Sub Command1_Click ( ) Dim num As Single num = 7 Do While num <> 0 num=num-2Loop End Sub

Note: ► Read: Schneider (Section 6.1) ► Read comments and do practice problems of these sections of these sections ► Attempt some questions of Exercises