when first typing-in a program, it is good practice to leave large enough intervals in-between the numbers.

You'll also notice, that for line 15 there's no LET keyword although the = remains. That is because LET is optional and it's implied from the assignment alone. Functionally therefore, lines 10 and 15 are identical. For this chapter, we will keep using LET so you can see the assignments clearly but further on, we will skip them altogether as they make for much more readable code.

Note here that we will do the same with the printed representation of Syntax Highlighting as it requires a contrast with the background which a printed manual doesn't provide.

Variables and Arrays

Before we continue further, let's take a pause and discuss what the letters a and b in the examples above are called. We call these variables because they represent locations in the computer's memory where we can temporarily store information to be recalled and used at any time a program is being executed. There are two types of variables by usage: Global and Local. Global variables apply to an entire NextBASIC program and these are the ones we will talk about here. Local variables, apply only to subprogram areas we call procedures and functions and they will be discussed in the respective chapters.

NextBASIC can store two types of information in memory: numbers and text. Numbers are further separated into floating point and integers. Text variables are called strings and they will be discussed in Chapter 7. Furthermore, NextBASIC can group together variables of the same type and refer to them collectively. These groupings are called arrays.

There are some restrictions in the naming and quantity of available variables and arrays as you can see in the following table according to their type. It is advisable to make use of integer variables over their regular numeric counterparts despite their restrictions1 at least where speed of execution is concerned.

Integer variables Numeric variables String Variables
Qty Fixed 26 Limited only by memory Limited only by memory
Naming Single character prefixed by the % symbol Combination of characters and numbers Combination of characters and numbers suffixed by the $ symbol
Arrays Fixed 26 with maximum 64 elements (0...63)
Extensible size and dimensions (by reducing the number of available arrays)
Limited only by memory
(Indices are 1-based)
Limited only by memory
Indices are 1-based)

Table 1 – Types of NextBasic variables

Assignments

We saw earlier that using LET with a variable together with the symbol = and some value is called an assignment. What actually happens is that LET instructs NextBASIC to move a value (numeric or character) into a location in the computer's memory which we can later identify and recall by an easy-to-use name (See Table 1 above). Unlike previous versions of Sinclair BASICs that required the LET command and only allowed a single LET command per assignment, NextBASIC allows the omission of the LET keyword altogether (as the assignment operator = implies its use anyway) while, at the same time, multiple assignments of variables per LET command. In other words, the full form of LET is:

[LET] variable1 [,[variable2....variablen]] = value1[,[value2...valuen]]

Moreover, assignments allow multiple destinations and a mix of types of value and variables. Some examples of the above are:

LET x,y=10,20

1 Integer variables in NextBASIC are 16-bit (unsigned or signed). That means that they accept values from 0 to 65535 (or from -32768 to 32767)


ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.