Smart BASIC Programming. Lesson 6
Posted: Fri Nov 14, 2014 5:59 am
Lesson 6 - Simplicity and variety
In smart BASIC you can use short notation for math operations if they are using the same variable. For example strings:
can be written as:
If array has no more than 10 values then it can be used immediately, without creating it.
Any numeric variable or array value is zero by default until it is changed. Similarly, any unused string value is an empty string "".
Such double-word commands as END IF or END DEF can be written without space between words: ENDIF, ENDDEF.
Labels can be not only literal as
but also numerical. In this case colon is not used:
Comments can be not only single-line using character " ' ", but also multi-line using characters "/*" and "*/":
If IF THEN ELSE command has GOTO command after THEN or ELSE, then GOTO command can be omitted, so:
can be written as:
In smart BASIC subroutines can be used. Subroutine is a code which is executed by GOSUB command, and after it finishes with RETURN command the program continues to run from the place where subroutine was called:
As subroutine name is a label, it can also be numerical:
It is possible to write several commands in one line using separator "!":
EXERCISE 7
Carefully read "Basics" section in documentation, test those smart BASIC features which are interesting to you, and ask questions on Forum if something will remain unclear.
In smart BASIC you can use short notation for math operations if they are using the same variable. For example strings:
Code: Select all
A = A + 1
B = B * A
M (K) = M (K) / 3
Code: Select all
A += 1
B *= A
M (K) /= 3
Any numeric variable or array value is zero by default until it is changed. Similarly, any unused string value is an empty string "".
Such double-word commands as END IF or END DEF can be written without space between words: ENDIF, ENDDEF.
Labels can be not only literal as
Code: Select all
LOOP: GOTO LOOP
Code: Select all
10 GOTO 10
Code: Select all
'single-line comment
/* multi-line
comment */
Code: Select all
IF A = B THEN GOTO 1
Code: Select all
IF A = B THEN 1
Code: Select all
PRINT "before subroutine"
GOSUB SUBPROG
PRINT "after subroutine"
END
SUBPROG:
PRINT "inside subroutine"
RETURN
Code: Select all
PRINT "before subroutine"
GOSUB 1
PRINT "after subroutine"
END
1 PRINT "inside subroutine"
RETURN
Code: Select all
A = 1 ! B = 2 ! PRINT A + B
Carefully read "Basics" section in documentation, test those smart BASIC features which are interesting to you, and ask questions on Forum if something will remain unclear.