Welcome to my third tutorial. In this one we will cover DIM, GOTO, GOSUB, FOR...NEXT It is assumed that you all there is to know from my other two tutorials. DIM --- The first thing I'm going to teach you is DIM this can be very useful when using varaibles. For example, say you had a program that required 500 variables all based on the same thing, lets say 500 names in an address book, you don't want to have to type out 500 different varaibles. Ever since the beginning of computer programming, programmers have tried to find quicker and easier ways to do something. This is one of them. DIM can be used to create loads of varaibles in just one command. It works like this: DIM NAMES$ (500) This an 'array' of names from 0 to 500 (so theres actualy 501 different variables made here) To give one of the varaibles a value do the following: LET NAME$(5) = "OLD MAN" This will give the 6th variable the value 'OLD MAN' (Remember that zero counts as a variable) Well that wasn't too hard now was it. So this should be a breeze: '-------------------- DIM NAME$ (500) LET N% = 5 LET NAME$(5) = "OLD MAN" CLS PRINT NAME$(N%) '-------------------- The number that is used with an array can be a variable too, this is shpwn in the program above. The output from the program should be obvious: OLD MAN As an array can be called using a variable this means that you can create nested arrays: '-------------------- DIM NAME$ (500) DIM NUM% (10) LET N% = 4 LET NUM%(4) = 5 LET NAME$(5) = "OLD MAN" CLS PRINT NAME$(NUM(N%)) '-------------------- If you don't understand this straight away then don't worry just read over it few times, I'm sure you'll get it. Arrays are usually defined at the beginning of a program, or at least before they aere used. GOTO ---- This is a can be a useful statement, it is used to make the program execution movce to another location in the program. To use GOTO you have to fisrt of all make a 'tag' for the program to jump to. Have a look at this: '-------------------- CLS PRINT "WHAT A NICE DAY" GOTO COMEHERE PRINT "GOODBYE 1" COMEHERE: PRINT "GOODBYE 2" '-------------------- As you can see a 'tag' must have a colon at the end. When run you should get this output: WHAT A NICE DAT GOODBYE2 This is because the GOTO moves or jumps to the tag and continues from there. You must not have two tags with the same name. Tags are used by GOTO as a 'look up' spot, when they encontered during normal execution they are simply ignored. It is possible to make and endless loop using goto, look: '-------------------- CLS START: PRINT "HELLO" GOTO START '-------------------- This program will go on for ever, in an endless loop. To stop it press CTRL & Break buttons to stop the program manually. Well thats all there is to kow about GOTO! Lets move onto GOSUB GOSUB ----- GOSUB works similar to GOTO but with one difference, have a look at this: '-------------------- CLS PRINT "WHAT A NICE DAY" GOSUB COMEHERE PRINT "GOODBYE 1" END COMEHERE: PRINT "GOODBYE 2" RETURN '-------------------- This program introduces you to two new commands, the END command and the RETURN command. END is a basic command which does exactly what it is called it will cease execution regardless of whether there is still more code or not. The RETURN statement is used with GOSUB to return to the line AFTER the initial GOSUB. So the output is: WHAT A NICE DAY GOODBYE 2 GOODBYE 1 Have a go practicing what you have learnt so far. FOR...NEXT ---------- This is actually two statement, FOR and NEXT. These are used to make a different type of loop. Look at the following example: '-------------------- FOR N% = 1 TO 20 CLS PRINT "HELLO WORLD ";N% NEXT N% '-------------------- This program will look around 20 times. The FOR statement sets up a loop, this stuff directely after is a test, the variable N% is used, and everytime the program loops it is incremented by 1 and once it reaches 20 the loop breaks and continues with the rest of the program. This is another example of this type of loop '-------------------- FOR X = 1 TO 100 FOR Y = 1 TO 100 CLS PRINT "X:";X PRINT "Y:";Y NEXT Y NEXT X '-------------------- This example uses nested loops and the values are printed on the screen. This type of program could be used for graphics where a pixel is made to draw a line. I have also used tabs to tidy up my program, in long programs tabs can make the code easier to read. When this program is run you will find the text written on the screen flashes alot,this is because the CLS is constantly clearing the screen, an improvement on this program is this: '-------------------- FOR X = 1 TO 100 FOR Y = 1 TO 100 LOCATE 1,1 PRINT "X:";X PRINT "Y:";Y NEXT Y NEXT X '-------------------- The LOCATE statement can be used to set the location of a PRINT statement, the first value is the row number and the second is the column number. Using this method also increases the speed of the execution. try to get to grips with FOR..NEXT loops, GOTO, GOSUB, LOCATE, etc they can be very powerful tools when making larger, more cimplicated programs. Thats all for this one. Bye