Smart BASIC Programming. Lesson 6

Post Reply
User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Smart BASIC Programming. Lesson 6

Post by Mr. Kibernetik »

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:

Code: Select all

A = A + 1
B = B * A
M (K) = M (K) / 3
can be written as:

Code: Select all

A += 1
B *= A
M (K) /= 3
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

Code: Select all

LOOP: GOTO LOOP
but also numerical. In this case colon is not used:

Code: Select all

10 GOTO 10
Comments can be not only single-line using character " ' ", but also multi-line using characters "/*" and "*/":

Code: Select all

'single-line comment
/* multi-line
comment */
If IF THEN ELSE command has GOTO command after THEN or ELSE, then GOTO command can be omitted, so:

Code: Select all

IF A = B THEN GOTO 1
can be written as:

Code: Select all

IF A = B THEN 1
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:

Code: Select all

PRINT "before subroutine"
GOSUB SUBPROG
PRINT "after subroutine"
END
SUBPROG:
PRINT "inside subroutine"
RETURN
As subroutine name is a label, it can also be numerical:

Code: Select all

PRINT "before subroutine"
GOSUB 1
PRINT "after subroutine"
END
1 PRINT "inside subroutine"
RETURN
It is possible to write several commands in one line using separator "!":

Code: Select all

A = 1 ! B = 2 ! PRINT A + B
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.

alinc
Posts: 4
Joined: Thu Aug 31, 2017 8:17 pm
My devices: ipad, iphone
Flag: United States of America

Re: Smart BASIC Programming. Lesson 6

Post by alinc »

Does Smart Basic have a Select Case function?

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Smart BASIC Programming. Lesson 6

Post by Mr. Kibernetik »

alinc wrote:
Wed Sep 13, 2017 6:55 pm
Does Smart Basic have a Select Case function?
What does "select case" function do?

alinc
Posts: 4
Joined: Thu Aug 31, 2017 8:17 pm
My devices: ipad, iphone
Flag: United States of America

Re: Smart BASIC Programming. Lesson 6

Post by alinc »

It's a multi-way branch. Executes the statements after
the CASE statement which matches the SELECT CASE
expression, then skips to the END SELECT statement.
If there is no match, and a CASE ELSE statement is
present, then execution defaults to the statements
following the CASE ELSE.
Example:
select case x
case 2
...
case 3, 4
...
case else
...
end select

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Smart BASIC Programming. Lesson 6

Post by Mr. Kibernetik »

No, in smart BASIC there is no such construction.

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Smart BASIC Programming. Lesson 6

Post by GeorgeMcGinn »

Yes, it does not have this construction, but I have to find it and finish it.

I was working on a FUNCTION that, while ugly looking, simulates this feature. I never finished it, and I think it is among the thousands of Dropbox files I have.

I was having the issues with the functions with a function or something like that, and since I started this code when I first started using SB, I dropped it.

It is a nice to have, but it only makes sense to use this in certain situations. Nothing a series of IF statements can't handle.
Mr. Kibernetik wrote:
Wed Sep 13, 2017 7:09 pm
No, in smart BASIC there is no such construction.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Post Reply