# Liberty BASIC

Paradigm procedural , Event Carl Gundel Shoptalk Systems 1992 4.04 / 31.07.2010 Microsoft Windows (Mac OS X and Linux in Liberty Basic 5) commercial .bas, .tkn, .fr3 http://www.libertybasic.com/ LB Booster, GLBCC Just BASIC QuickBASIC Run BASIC, Leopard

Liberty BASIC — a commercial programming language from BASIC family and the development environment for it. Is the interpreter and supports 16-and 32-bit Windows and OS/2. Liberty BASIC was created by Karl Gandel on Smalltalk and released by its Shoptalk Systems company in 1992. Its last version 4.04 appeared on July 31, 2010. The version for OS/2 very old, but free. In the developed version 5 support of Windows, Mac OS X and Linux is declared.

This language is was created and designed mainly for training in programming.

The environment of development of Liberty BASIC includes the editor of a code, a debugger, and also, in the latests version, the observer of interactive lessons.

## Literals

A literal value is hard-coded into a program. Here are two literals, printed to the mainwin. The first is a number. The second is a string of text characters.

print 57
print "Hello World"

produces
57
Hello World

## Variables

A variable is a name used in the code that represents a string or numeric value. The value assigned to the variable name may change as the program runs. The program can always access the current value of the variable by refering to its name. In this example, a value of "3" is assigned to a variable called myNumber:

myNumber=3
print myNumber

produces
3

### String variables

String variable names must end with a $ (dollar sign). Text is assigned to a string variable using the equals sign ( = ). This example assigns "Hello World" to the string variable hello$ and then prints it in the mainwin.

hello$= "Hello World" print hello$

The program above produces this in the mainwin:
Hello World

NOTE- a string can have zero characters. Such a string is often called an empty string. In BASIC, an empty string can be expressed in a string literal as two quotation marks without any characters between them. For example (noCharactersHere$ is the name of our string variable): let noCharactersHere$ = ""

### Global

In general, variables used in the main program code are not visible inside functions and subroutines. Variables inside functions and subroutines are not visible in the main program.c Liberty BASIC 4 introduces the GLOBAL statement to create global variables. Variables declared as GLOBAL can be seen everywhere in a program. The special system variables like WindowWidth, WindowHeight, etc. now have true global status. GLOBALS are specified and used like this:

global true, false, filename$true=1 false=0 filaname$ = "readme.txt"

## Looping

Liberty BASIC provides three constructions for looping. One is FOR/NEXT another is WHILE/WEND, and the third is DO LOOP.

### For/next

The FOR . . . NEXT looping construct provides a way to execute code a specific amount of times. A starting and ending value are specified:

for var = 1 to 10
{BASIC code}
next var

In this case, the {BASIC code} is executed 10 times, with var being 1 the first time, 2 the second, and on through 10 the tenth time. Optionally (and usually) var is used in some calculation(s) in the {BASIC code}. For example if the {BASIC code} is print var ^ 2, then a list of squares for var will be displayed upon execution.

The specified range could just as easily be 2 TO 20, instead of 1 TO 10, but since the loop always counts +1 at a time, the first number must be less than the second. The way around this limitation is to place STEP n at the end of for FOR statement:

for index = 20 to 2 step -1
{BASIC code}
next index

### While/wend

As shown above, Liberty BASIC includes a for/next looping construct. It also has a while/wend looping construct. Here is the above program rewritten using while/wend.

'count to ten
x = 0
while x < 10
x = x + 1
print x
wend
end

One useful thing that can be done with while/wend is to wrap the boolean expression in a NOT() function, which effectively turns while/wend into a "while condition is false" do construct:

'count to ten
while not(x = 10)
x = x + 1
print x
wend
end

### Do loop

Liberty BASIC also provides a DO LOOP structure for cases when you want a loop that always executes once and then only loops back as long as a condition is met. It will continue looping back and executing the code as long as the booleanExpr evaluates to true. Here is the routine that counts to 10 using DO LOOP with while and DO LOOP with until.

'count to 10 using "loop while" and "loop until"
do
print a
a = a + 1
loop while a < 11

do
print b
b = b + 1
loop until b = 11

## Arrays

Liberty BASIC supports single and double dimensioned arrays. These can be defined as string or numeric arrays. The extents of the dimensions can be in excess of 2 million elements, if there is enough RAM available.

Arrays that contain more than 10 elements must be dimensioned before they can be used. Arrays are dimensioned with the DIM statement.

DIM students$(20) DIM ages(100) Resizing is done to any array with the REDIM statement, but doing so will erase the contents of the array. REDIM students$(30)

Double dimensioned arrays must always be dimensioned with the DIM statement before use.

DIM scores$(20, 10) The equal sign ( = ) is used to assign a value to an element in an array. The element is referred to by its index number. The index may be expressed as a literal number or as a numeric variable. The element at index 2 in the following example is filled with "John." The element at index 7 is filled with the number 12. students$(2) = "John"
ages(7) = 12

## Sub

sub subName ''zero or more comma separated parameter variable names''
'code for the sub goes in here
end sub

Description:
This statement defines a subroutine. Zero or more parameters may be passed into the subroutine. A subroutine cannot contain another subroutine definition, nor a function definition.

The CALL statement is used to access the SUBROUTINE and to pass values into it. The values must be the same type as the SUB statement defines them to be. So the following example:

sub mySubName string$, number, string2$

is called like this:
end

### The program opens a window for input

nomainwin
prompt "Enter your name:"; response $notice "Response:" + chr$ (13) + response \$
end

### Running third-party application

nomainwin
end