This document discusses arrays in BASIC programming. It defines arrays as collections of variables with the same name identified by subscripts. Arrays can be one-dimensional like lists or two-dimensional like tables. Values are assigned to subscripted variables using LET, READ, or INPUT statements. The DIM statement reserves memory for large arrays. Two-dimensional arrays use doubly subscripted variables and nested loops can be used to fill and print them. Arrays can manipulate data through operations like finding elements, matching between arrays, and sorting.
2. Array
• An array is a set of like variables arranged in
sequence identified by their subscripts.
OR
An array is a collection of subscripted variables
with the same variable name.
List and tables are called arrays. A list is referred
to as one-dimensional array and a table as two-
dimensional array.
Hamza Mohammad Iqbal
3. Subscripted Variable
• Subscripted variable names are similar to
simple variable names except that they are
followed by a subscript.
• Subscript must be either zero or a positive
integer and must always be enclosed in
parentheses.
• For example A(2) , B$(4).
Hamza Mohammad Iqbal
4. Storage in subscripted variable
• Each subscripted variable is used to store one
number or string.
• Values are assigned to the subscripted
variables by LET, READ or INPUT statements.
Hamza Mohammad Iqbal
5. Filling an array
• Strings or numbers assigned to subscripted
variables in arrays using LET READ or INPUT
statement is called filling an array.
• For e.g.
• 10 READ ART$(1),ART$(2)
• 20 DATA PEN,BOOK
• END
Hamza Mohammad Iqbal
6. BIG ARRAYS : DIM
• DIM is a short name used for DIMension.
• It is used to declare an array especially to specify
more than 10 subscripts.
• DIM statement causes the computer to reserve
more spaces in its memory required for big
arrays.
• The number of subscripted variables can be
increased including the DIM statement in an array
program.
• Syntax: Line# DIM <VariableName> (subscripted value)
Hamza Mohammad Iqbal
7. Error without using DIM
• When you run a program of an array to store
more than 10 values. In the output you got
the error such like BAD subscript error in line#
because the computer ordinarily reserves
memory spaces for only 11 elements of an
array.
Hamza Mohammad Iqbal
8. Two Dimensional Array
• Two dimensional arrays are named the same
way as one-dimensional arrays.
• Elements in a two-dimensional array are
commonly referred to as doubly-subscripted
variables.
• Format: Line# DIM (Array Name) (row,column)
Hamza Mohammad Iqbal
9. Filling two dimensional array
• One way of filling a two dimensional array is by FOR …. NEXT nested loops.
• For e.g.
• 10 DIM D(4,3)
• 20 FOR ROW = 1 TO 4
• 30 FOR COL = 1 TO 3
• 40 READ D(ROW,COL)
• 50 NEXT COL
• 60 NEXT ROW
• 70 DATA 3,5,6
• 80 DATA 76,5,3
• 90 DATA 45,4,74
• 100 DATA 34,65,7
• 110 END
Hamza Mohammad Iqbal
10. PRINTING TWO DIMENSIONAL ARRAY
• 10 DIM D(4,3)
• 20 FOR ROW = 1 TO 4
• 30 FOR COL = 1 TO 3
• 40 READ D(ROW,COL)
• 50 NEXT COL
• 60 NEXT ROW
• 70 PRINT “PRINT TWO DIMENSIONAL ARRAY”
• 80 FOR ROW = 1 TO 4
• 90 FOR COL = 1 TO 3
• 100 PRINT D(ROW,COL);
• 110 NEXT COL
• 120 PRINT
• 130 NEXT ROW
• 170 DATA 3,5,6
• 180 DATA 76,5,3
• 190 DATA 45,4,74
• 200 DATA 34,65,7
• 210 END
Hamza Mohammad Iqbal
12. Manipulating data with Arrays
• Numerous operations on data can be
performed using arrays. Such as finding
particular element in an array, matching
elements from two arrays and sorting an
array.
• Important use of arrays is to store data that
are used later for comparison.
Hamza Mohammad Iqbal