I Want 2 Learn 2‎ > ‎Xtra‎ > ‎

Basic BASIC

Some basic commands to get you started

PRINT
FOR
STEP
IF
THEN
ELSE
END IF
END FOR
REM

Using two keywords PRINT & FOR this simple program prints to the screen the numbers from 1 to 15. END statements generally mean this is where the routine ends or loops back if a condition hasn't been met. e.g. the FOR, END FOR loop will continue until the number held in f ( a variable ) has reached its goal, in this case 15 
 
Variables are like little boxes that can contain anything, in this case it is a whole number (INTEGER) which changes from 1 to 15 each time the 'END FOR f' loops

10 FOR f = 1 to 15        REMark      <-------|
20   PRINT f,                  REMark          a for/next loop
30 END FOR f                REMark      <-------|


Using PRINT & FOR and STEP this program prints to the screen the odd numbers from 1 to 15

10  FOR f = 1 to 15 STEP 2
20    PRINT f,
30  END FOR f


This program prints on to the screen the odd numbers up to 15, and anything over ten gets a star * even if ten doesn't get printed

10 FOR f = 1 to 15 STEP 2
20   PRINT f,
30    IF f>10 THEN
40     PRINT "*"
50   ELSE
60     PRINT
70   END IF
80 END FOR f


Although you may not think it necessary, it is useful to put in REM statements in all the code you write as :

one
: as a reminder for what the code is doing

two
: to explain difficult or complex pieces of code that are not immediately obvious, especially when you leave the code to do something else for a few months thinking, that's easy, I will remember that when I get back to doing some more, well I have news for you, you won't, not without remarks, or atleast not straight away.

three
: so that other people can understand what your code is doing should you make it public or available to a community, such as Quanta or the QL community



Although you may not think it necessary, it is useful to indent code, especially that which has a start and finish and subsequent code would also be indented as:

one
: as a reminder for what the code is doing

two
: to explain pieces of code that are not immediately obvious, visually, indentation makes it easier to see, an aesthetic to coding, it is good and professional practice, get in to the habit of doing it.

three
: so that other people can understand what your code is doing should you make it public or available to a community, such as Quanta or the QL community


Common Line Commands

Ed(it)
Run
Save
Load
List

Type in ED(it) [line-number] and type in each line followed by pressing the down arrow (to go to the next line) or ENTER (to finish)
 
Type in RUN and press ENTER to 'run' the programme
 

QL Keyboard operations

Left Arrow - Moves the cursor left
Right Arrow - Moves the cursor right
Up Arrow - Moves the cursor up
Down Arrow - Moves the cursor down

Ctrl + left arrow - Removes the character to the left of the cursor
Ctrl + right arrow - Removes the character to the right of the cursor




REM is short for REMark and it is a comment you can put in your code which is ignored by the SuperBASIC interpreter, for example using REM statements in the above code could look like this

9 REMark This routine prints out odd numbers
10  FOR f = 1 to 15 STEP 2
20    PRINT f,
25     REMark Now check to see if 'f'' is more than 10
26     REMark if so print a star (*)
30      IF f>10 THEN
40        PRINT "*"
50      ELSE
60        PRINT :REMark Try leaving this out and see what happens
70      END IF
80  END FOR f