Quick Start Guide: Difference between revisions

From Liberty BASIC Family
Jump to navigation Jump to search
No edit summary
No edit summary
Line 38: Line 38:
     print "Bye."
     print "Bye."
     end
     end
</source>
=== Variables ===
Liberty BASIC has two variable types, numeric and string.  Consistent with the classic BASIC languages, variables in Liberty BASIC do not need to be declared before they are used.
Numeric variables are formed as letters and digits and must start with a letter.  String variable names follow the same rules but end with a dollar sign $.
<source lang="lb" highlight="">
'Examples of numeric variables, which can hold either integer or floating point values.
count1 = 123
count2 = 234
count3 = 100
averageCount = (count1 + count2 + count3) / 3
print averageCount
</source>
When run, this code prints the number 152.333333.
<source lang="lb" highlight="">
'Examples of string variables. Notice that they do not need to be declared with DIM or other command.
firstName$ = "Jerry"
secondName$ = "Mandell"
fullName$ = secondName$ + ", " + firstName$
print fullName$
</source>
When run, this code print Mandell, Jerry.
Variable names can also have periods in them, like so:
<source lang="lb" highlight="">
first.name$ = "Jerry"
member.id = 21412
</source>
</source>
=== Numbers ===
=== Numbers ===

Revision as of 00:51, 1 January 2024

Quick Start Guide

Liberty BASIC has some unique features that are not in other versions of BASIC. This section will explain these features.

Note: Just BASIC and Run BASIC also share the same language features, and any exceptions will be noted.

Branch Labels

Many BASIC languages support line numbers, and Liberty BASIC also lets you use them, but it is really intended that the programmer use named branch labels instead.

Branch labels are letters and numbers surrounded by square brackets, for example: [exampleBranchLabel] or [letters123]

So, instead of using line numbers like so:

10 input "What is your name?"; yourName$
20 print "Nice to meet you, "; yourName$
30 input "Ask again (Y/N)"; yn$
40 if yn$ = "Y" or yn$ = "y" then 10
50 print "Bye."
60 end

The simplest example of this without line numbers is:

[ask]
    input "What is your name?"; yourName$
    print "Nice to meet you, "; yourName$
    input "Ask again (Y/N)"; yn$
    if yn$ = "Y" or yn$ = "y" then [ask]
    print "Bye."
    end

Notice that we only need one branch label instead of a program written using the line numbered style which has a line number for each line of code.

Here is what the same program looks like in QBasic:

ask:
    input "What is your name?"; yourName$
    print "Nice to meet you, "; yourName$
    input "Ask again (Y/N)"; yn$
    if yn$ = "Y" or yn$ = "y" then ask
    print "Bye."
    end

Variables

Liberty BASIC has two variable types, numeric and string. Consistent with the classic BASIC languages, variables in Liberty BASIC do not need to be declared before they are used.

Numeric variables are formed as letters and digits and must start with a letter. String variable names follow the same rules but end with a dollar sign $.

'Examples of numeric variables, which can hold either integer or floating point values.
count1 = 123
count2 = 234
count3 = 100
averageCount = (count1 + count2 + count3) / 3
print averageCount

When run, this code prints the number 152.333333.

'Examples of string variables. Notice that they do not need to be declared with DIM or other command.
firstName$ = "Jerry"
secondName$ = "Mandell"
fullName$ = secondName$ + ", " + firstName$
print fullName$

When run, this code print Mandell, Jerry.

Variable names can also have periods in them, like so:

first.name$ = "Jerry"
member.id = 21412

Numbers

Liberty BASIC has only two numeric types, integers and floats.

Integers in Liberty BASIC are kept in two formats, 31 bit (-1073741824 to 1073741823) and arbitrary length integers which are outside the range of the 31-bit integers.

Floats in Liberty BASIC are double precision using the IEEE 754 specification. All floating point math is done using the computer's math coprocessor (more specs later).

Conversion between the two integer formats and floating point is automatically handled behind the scenes. The programmer does not need to do anything.

More to come...