QUICK Tutorial Part 2 - By Dean Garraghty
(c)1994 Dean Garraghty
Quick is still available from us: www.dgs.clara.net
Last time we looked at how to implement a FOR...NEXT loop in QUICK.
This time we'll get a little more advanced and look at string handling
and ARRAYs. Simple graphics will come in Part 3 next issue!
In Basic, a string is simply defined at the start of the program by
using the DIM statement, followed by the variable name and its maximum
length. E.g. DIM TEST$(20) would create a string called TEST which
could hold a maximum of 20 characters. QUICK handles strings in a
similar, but surprising, way. In QUICK a string is actually treated as
an ARRAY. Why is this? Well, a string is basically an array of
individual characters. Most procedural programming languages work this
way. Again, Basic is a bit of a black sheep! Consider these two
programs which do exactly the same thing:
Basic QUICK
5 DIM NAME$(20) ARRAY
10 PRINT"ENTER YOUR NAME" [
20 INPUT NAME$ NAME(20)
30 PRINT"HELLO ";NAME$ ]
MAIN
PRINT("ENTER YOUR NAME")
INPUT(NAME)
PRINT("HELLO ",NAME)
ENDMAIN
As you can see, the QUICK version uses an array to hold the string. In
Basic we use the $ symbol to denote the variable as a string. In QUICK
we don't do this. ARRAYs are not only used for strings in QUICK. They
can be used to hold data as well. Consider these two programs, which do
exactly the same thing:
Basic QUICK
10 DIM NUMBERS(9) ARRAY
20 RESTORE 70 [
25 FOR X=0 TO 9 NUMBERS(10)
30 READ TEMP ]
40 NUMBERS(X)=TEMP BYTE
50 NEXT X [
55 FOR Y=0 TO 9 X
60 PRINT NUMBERS(Y) TEMP
65 NEXT Y ]
70 DATA 1,2,3,4,5,6,7,8,9,0 MAIN
DATA(NUMBERS)
[
1,2,3,4,5,6,7,8,9,0
]
X=0
TEMP=0
WHILE X<10
TEMP=NUMBERS(X)
PRINT(TEMP)
X+
WEND
ENDMAIN
You should, hopefully, be able to follow the Basic code. Now let's
discuss the QUICK code. First of all we have to define an ARRAY
variable to hold our data. We will call this NUMBERS, but we could have
called it almost anything. Basic and QUICK differ when defining ARRAYs.
The ARRAY in our case is to hold 10 numbers. In both Basic and QUICK these
numbers are internally indexed 0 to 9. That means the first number of the
ARRAY is actually cell 0. In Basic we define NUMBERS with DIM NUMBERS(9),
but in QUICK we define NUMBERS as an ARRAY of 10. This is where Basic and
QUICK differ. However, when using the array, Basic and QUICK are the same.
In our example, the number 5 in our array is actually accessed by
NUMBERS(4).
QUICK has a facility for loading data straight into an ARRAY, but Basic
hasn't, so you have to use a FOR...NEXT loop. In QUICK we used
DATA(NUMBERS) followed by our data list contained in [ ]. All we had to
do then was print the ARRAY to the screen. This was done using a WHILE
loop. TEMP is a temporary variable used to hold the contents of each
cell of the array before printing. Notice WHILE X<10, because the cells
are numbered 0 to 9.
When you run the QUICK program you will notice that the numbers appear
on the screen straight away, but the Basic program takes a bit of time
before the numbers appear!
I've gone through quite a bit this issue, so I'll let your head have a
rest now! As usual, the best way to understand all of this is to get
your QUICK disk out and have a fiddle! See you next time!
Originally published in The Atari 8-bit News-Paper.
Click here to Return to the Articles Main Menu