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

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1.
Advertisements

Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
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.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Introduction to Computing Dr. Nadeem A Khan. Lecture 23.
Introduction to Computing Dr. Nadeem A Khan. Lecture 22.
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.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
CS150 Introduction to Computer Science 1
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 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 6.
Introduction to Computing Dr. Nadeem A Khan. Lecture 28.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
Chapter seven review. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For.
JAVA 1.5 New Features Dr V. The syntax of the enhanced for loop (for each) for (type variableName : arrayName) { statements } arrayName could be any.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Introduction to Computing Dr. Nadeem A Khan. Lecture 18.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Arrays. What is an Array? Similar to a Matrix. Collection of data that needs similar processing. Example: Transpose of a matrix.
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.
Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
IE 212: Computational Methods for Industrial Engineering
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
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.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
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.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Chapter 71 Arrays Creating and Accessing Arrays Using Arrays Some Additional Types of Arrays.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
2016 N5 Prelim Revision. HTML Absolute/Relative addressing in HTML.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Chapter81 For....Next Loops n For i = m To n statement (s) Next i n For statement designates a numeric variable, called control variable. n It is initialized.
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. ◦
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
Asserting Java © Rick Mercer Chapter 7 The Java Array Object.
© Rick Mercer Chapter 7 The Java Array Object.  Some variables store precisely one value: a double stores one floating-point number a double stores one.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
for Repetition Structures
Chapter 7 Arrays.
For...Next Statements.
Presentation transcript:

Introduction to Computing Dr. Nadeem A Khan

Lecture 24

► The general format with step of 1: For i = m To n Statements Next i For…Next Loops

► Convert to For.. Next Loop Sub Command1_Click ( ) Dim num As Integer Let num=1 Do While num<=10 Picture1.Print num; Let num=num+1 Loop End Sub For Next Loops

► Example with For.. Next Loop Sub Command1_Click ( ) Dim num As Integer For num=1 To 10 Picture1.Print num; Next num End Sub For Next Loops

► The result: For Next Loops

► The general format with steps: For i = m To n Step s Statements Next i => Each time increment: i = i + s; m, n, s could be numeric expressions m, n, s could be numeric expressions For…Next Loops

► Example with For.. Next Loop with steps Sub Command1_Click ( ) Dim num As Integer For num= 1 To 10 Step 2 Picture1.Print num; Next num End Sub The output? For Next Loops

► The result: For Next Loops

► Rewrite the following program using nested For.. Next Loop Nested Loops: For…Next

Sub Command1_Click ( ) Dim num As Integer, counter As Integer Let counter=1 Do While counter<=4 Let num=1 Let num=1 Do While num<=10 Picture1.Print num; Let num=num+1 Loop Let counter=counter+1 Picture1.PrintLoop End Sub Nested Loops: For…Next

Sub Command1_Click ( ) Dim num As Integer, counter As Integer For counter = 1 To 4 For num =1 To 10 For num =1 To 10 Picture1.Print num; Next num Picture1.Print Next counter End Sub Nested Loops: For…Next

► The result: Nested Loops

► Reverses the input string Sub Command1_Click ( ) Picture1.Cls Picture1.Print Reverse$((Text1.Text)) End Sub For Next Loops

Function Reverse$ (info As String) Dim m As Integer, j As Integer, temp As String Let temp = “” For j = Len(info) To 1 Step -1 Let temp = temp + Mid$(info, j, 1) Next Reverse$ = temp End Function For Next Loops

► Exit For: Works similar as Exit Do Exit For

Note: ► Read: Schneider Chapter 6, Warner Chapter 6 ► Read comments and do practice problems of these sections of these sections ► Attempt some questions of Exercises

Chapter 7: Array Variables (Arrays)

► Array:  A list of values can be assigned  Collection of variables of the same type Array Variables (Arrays)

► Array Declaration: Dim arrayName (1 to n) As varType e.g: Dim names(1 To 3) as Strings Dim scores(1 To 10) as Single Array Variables (Arrays)

► Value assignment: Dim names(1 To 3) as Strings Let names(1)=“Aslam” Let names(2)=“Khalid” Let names(3)=“Akbar” Picture1.Print names(3), names(2),names(1) Array Variables (Arrays)

► What is what? Dim scores(1 To 3) as Single scores( ): name of the array scores(1): first element scores(2): second element scores(3): third element 1, 2, 3: subscripts Array Variables (Arrays)

► What are the ranges or dimensions? Dim scores(1 To 3) as Single Dim names(1 To 10) as String Array Variables (Arrays)

End