Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS 106, Winter 2009 Class 19, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,

Similar presentations


Presentation on theme: "1 CS 106, Winter 2009 Class 19, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,"— Presentation transcript:

1 1 CS 106, Winter 2009 Class 19, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer, herb@cs.pdx.eduherb@cs.pdx.edu

2 2 IMPORTANT!! The final exam for Section 2 (MW eve) is at 7:30 pm. Sorry for the earlier error, and thanks to the student who pointed it out! The loop in Assignment 6 can start at 5 instead of 1.

3 3 Arrays Arrays are a way to structure multiple pieces of data of the same type In this way they resemble Excel columns You can perform operations on an array in an efficient way using loops.

4 4 VB Arrays In VB arrays are declared much like variables: Dim name As String Dim nameArray(20) As String This creates an array of 21 elements, numbered from 0 to 20 We want to start indexing at 1, so we will just ignore the 0 th element, and make our arrays have the number of elements we want, plus one

5 5 Things to watch out for with arrays You must be careful not to try to put more items in the array than it will hold (overflow). Doing so should cause a runtime error but may instead just result in mysterious bugs. You should not try to index beyond the end of an array. This should also cause a runtime error, but might just result in getting a strange answer back.

6 6 Array Demos The array demos show examples of reading data into an array from a file, and then performing various operations on it Note that the file should be in the debug folder of the bin folder inside the project (in case you want to play around with files)

7 7 BREAK 10 minutes

8 8 Recursion Recursion is a powerful technique for thinking about a process It can be used to simulate a loop, or for many other kinds of applications In recursion, a function or procedure calls itself Obviously, there is a danger of an infinite recursion, so there has to be a test for stopping it, and something (usually a parameter) must change between calls


Download ppt "1 CS 106, Winter 2009 Class 19, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,"

Similar presentations


Ads by Google