![]() |
B.5 Arrays |
Arrays are fundamental data structures that let you store a list of items in a single variable. Think of them as a set of numbered slots, each holding a value. In SheerPower, arrays are a simple way to manage lists, but it's also important to know when a more powerful tool, like a Cluster Array, is a better choice.
If you know exactly how many items you need to store, you can
create a fixed-size array using the dim
statement.
This creates an array that looks like this:
What if you create an array and later realize you need more
slots? You can use the redim
statement to expand it.
Importantly, redim
preserves all the existing
data in the array.
Visually, the `redim` operation does this:
What if you don't know the size at all and want to add items one by one? SheerPower has a special syntax for this: creating an array with a size of zero.
To add an item, you use a unique syntax: you assign the new value to index 0. This special operation appends the item to the end of the array, making it grow automatically.
Traditional arrays are great for simple lists of single values. However, most business data is structured. For example, instead of just a list of product names, you usually need to store the product's name, its price, and its quantity together.
For this kind of structured data, the Cluster Array is the preferred and more powerful tool in SheerPower. Think of it as a spreadsheet in memory, where each row is a complete record.
Hide Description
|
|
Enter or modify the code below, and then click on RUN |
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |