Ozapell Basic Learn Programming #7

Arrays are similar to normal variables except they contain one or more entries. Each entry is treated like a variable.

Here is an example of creating an array in Ozapell Basic:

MYARRAY=0

ARRAY=MYARRAY

RANGE=100

DIM

The variable MYARRAY is declared and given the value of 0. The ARRAY variable is given MYARRAY. RANGE will specify how many entries will be in the array. DIM changes the variable MYARRAY into an array containing 100 entries with the value of 0 in each.

If MYARRAY had been declared with a different initial value, then every entry would contain that value instead.

Here’s an example of an array working with strings:

MYSTRINGARRAY=”HELLO WORLD”

ARRAY=MYSTRINGARRAY

RANGE=20

DIM

This code will result in MYSTRINGARRAY containing 20 entries with the string “HELLO WORLD” in them.

Here is an example of an array of colors:

COLORS=COLORBLACK

RANGE=3

ARRAY=COLORS

DIM

COLORS=COLORGREEN

COLORS=COLORBLUE

COLORS=COLORRED

In this example, an array called COLORS is created with 3 entries containing the color black. Then each entry is initialized with a different color.

Arrays in Ozapell Basic will automatically advance to the next entry when the array is read or new data is written to it. If the array reaches the end, it will automatically circle back to the first entry.

The array index can also be set manually. This would be useful for random access to the array’s data.

Assuming the previous array COLORS has been declared…

ARRAY=COLORS

INDEX=0

ARRAYINDEX

This example will change the index (next entry to be used) in the array to 0. In Ozapell Basic, all arrays are indexed starting from 0. The first entry in every array is 0, the second entry is 1, etc.

Ozapell Basic on Steam

 

Advertisements
Ozapell Basic Learn Programming #7

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s