# 80-Bus News

## Summer 1985, Volume 4, Issue 2

MBASIC CBASIC = = or EQ < < or LT

= <= or LE O © or NE > > or GT

= >= or GE

The same letters are used for relational operators in FORTRAN which also uses the same set of logical operators — NOT, AND, OR and XOR — as both the BASICs.

Intrinsic functions

Most of the intrinsic functions in CBASIC are found in MBASIC. The exceptions are as follows:

FLOAT — converts an implicitly declared integer to its real number equivalent; if a real number is used instead, it is converted to an integer and then reconverted to its real equivalent.

INT% — this truncates a real number at the decimal point and returns an integer result. If a real number is to be converted, it is first converted to a real number before truncation. Note that this is not the same as the INT function which actually produces a real result.

This highlights the fact that unnecessary conversions and other operations will slow down a program, and to minimize this, one should make sure that any conversions are done using the right type of number.

User-defined functions

These are almost identical in both BASICs; the only major difference is that, in addition to the letters FN, up to 29 other alphanumeric characters may be added in CBASIC.

String functions

Compared with MBASIC, CBASIC has several more string functions; the following will give some idea of the flexibil’ty of this aspect of the dialect:

COMMAND\$ — returns the CP/M command line without the ndme of the CP/M program being invoked. You probably won’t use this a lot.

MATCH(AS,B\$,I%) — looks for string A\$ starting at the [%th character in string B\$. If it is present, the function returns the position in B\$ of the first A\$ character; if it is not present, the value 0 is returned. .

SADD(A\$) — returns the starting address in memory where CBASIC has stored A\$.

UCASE(A\$) — converts lower case letters to upper case in string A\$.

Program logic

in addition to the normal IF ... THEN ... <ELSE> statement, CBASIC has an amazing feature called the Compound IF statement where many comparisons can be made. A program which illustrates this and the use of other CBASIC features may help explain this very useful facility:

REM Silly program in CBASIC to illustrate REM ompound IF statement and other features. INPUT "ENTER THE VALUE OF THE COIN ";

COIN. VALUEZ COIN. COLGUR1\$="GOLD-COLOURED” : COIN. COLOURZ\$="SILVER" COIN. COLOUR3\$="BRONZE" PRINT*YOU INPUT A VALUE OF "; COIN. VALUEZ IF COIN. VALUEZ GT THAN 100 \ THEN PRINT’CAN’T DO THIS ONE!":GOTO 999 IF COIN. VALUEZ= 20 OR 100 THEN GOTO 10 IF COIN. VALUEZ=5 OR 10 OR 50 THEN GOTO 20 IF COIN. VALUEZ=1 OR 2 THEN GOTO 30 10 IF COIN. VALUEZ=20 THEN PRINT \ "YOUR COIN IS A 20p PIECE AND IT IS A”: PRINT’DIRTY YELLOW COLOUR":GOTO 999 IF COIN.VALUEZ EQ 100 – THEN PRINT" YOUR £1 COIN IS "; COIN .COLOURIE: | GOTO 999 20 IF COIN. VALUEZ EQ 50 \ THEN PRINT’ YOUR 50p COIN IS "05 COIN. COLOUR2\$:GOTO 999 IF COIN. VALUEZ LT 50 \ AND GT 5 THEN PRINTS "YOUR 10p COIN IS ";COIN.COLOUR2\$:GOTO 999 IF COIN. VALUEZ = 5 \ THEN PRINT" YOUR 5p COIN IS ";. COIN. COLOUR2\$:GOTO 999 30 IF COIN.VALUEZ LT 5 THEN PRINT "YOUR COIN IS A ":’ COIN. COLOUR3\$: IF COIN. VALUEZ NE 1 ‘ THEN PRINT" 2p PIECE” IF COIN. VALUEZ EQ 1 THEN PRINT” ip PIECE” 999 END

Another useful pair of statements found in both BASICs, is WHILEAVEND; they are essentially a variation of the FOR/NEXT statements and will allow statements inserted between them to be continually executed as long as the expression following WHILE is logically true. As soon as it is logically false, the sequence terminated and the next statement after WEND is executed. This is quite a nifty idea and additionally, Compound IF statements can be included between them. The following example illustrates the action of the WHILE/WEND pair:

This is an OCR’d version of the scanned page and likely contains recognition errors.