< A Level Computer Science Programming Guide

Declaring Arrays

In Pseudocode, Arrays all have declarable Upper and Lower bounds.

In VB.NET, Arrays all have declarable Upper Bounds, but Lower Bounds are always 0.

One Dimensional Arrays

Language General Usage Example Usage
Pseudocode
DECLARE <Identifier> : ARRAY[<Lower Bound>:<Upper Bound>] OF <Data Type>
DECLARE NameList : ARRAY[1:5] OF STRING
DECLARE YearlyRainfall : ARRAY[1900:2100] OF REAL
DECLARE AgeList : ARRAY[0:40] OF INTEGER
VB.NET
Dim <Identifier>(<Upper Bound>) As <Data Type>
Dim NameList(4) As String
Dim YearlyRainfall(200) As Double
Dim AgeList(40) As Integer
Python
<Identifier> = []
NameList = []
YearlyRainfall = []
AgeList = []

Two Dimensional Arrays

Language General Usage Example Usage
Pseudocode
DECLARE <Identifier> : ARRAY[<Lower Bound>:<Upper Bound>, <Lower Bound>:<Upper Bound>] OF <Data Type>
DECLARE GameArea : ARRAY[1:32, 0:16] OF STRING
DECLARE SudokuGrid : ARRAY[1:9, 1:9] OF INTEGER
DECLARE PopulationDensity : ARRAY[1:50, 20:50] OF REAL
VB.NET
Dim <Identifier>{<Upper Bound>, <Upper Bound>) As <Data Type>
Dim GameArea(31, 16) As String
Dim SudokuGrid(8) As Integer
Dim PopulationDensity(49,30) As Double
Python
<Identifier1> = []
<Identifier2> = []
<Identifier1>.append(<Identifier2>)
Game = []
GameArea = []
GameArea.append(Game)

SudokuX = []
SudokuGrid = []
SudokuGrid.append(SudokuX)

Longitude = []
PopulationDensity = []
PopulationDensity.append(Longitude)

Using Arrays

One Dimensional Arrays

Language General Usage Example Usage
Pseudocode
<Identifier>[<Index>] ← <Value>
NameList[1] ← "Stephen"
YearlyRainfall[1985] ← 13.73
AgeList[39] ← 17
VB.NET
<Identifier>(<Index>) = <Value>
NameList(0) = "Stephen"
YearlyRainfall(85) = 13.73
AgeList(38) = 17
Python
<Identifier>.append(<Value>)
NameList.append("Stephen")
YearlyRainfall.append(13.73)
AgeList.append(17)

Two Dimensional Arrays

Language General Usage Example Usage
Pseudocode
<Identifier>[<Index>,<Index>] ← <Value>
GameArea[16, 5] ← "Fire"
SudokuGrid[9, 3] ← 7
PopulationDensity[14, 32] ← 242.023
VB.NET
<Identifier>(<Index>,<Index>) = <Value>
GameArea(15, 5) = "Fire"
SudokuGrid(8, 2) = 7
PopulationDensity(13, 12) = 242.023
Python
<Identifier1> = []
<Identifier2> = []
<Identifier1>.append(<Identifier2>)
Game.append("Fire")
GameArea.append(Game)

SudokoX.append(7)
SudokuGrid.append(SudokuX)

Longitude.append(242.023)
PopulationDensity.append(Longitude)
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.