Martes, Enero 22, 2013

Introduction of BASIC Programming Language



The Basic Programming Language

History
BASIC
 in full Beginner's All-purpose Symbolic Instruction Code Computer programming language developed by John G. Kemeny and Thomas E. Kurtz (b. 1928) at Dartmouth College in the mid 1960's. One of the simplest high-level languages, with commands similar to English, it can be learned with relative ease even by schoolchildren and novice programmers. Since c. 1980, BASIC has been popular for use on personal computers.Basic is a very powerful language as a tool for the novice programmer. Basic allows for a wide range of applications, and it has many versions. However, as long as the emphasis is on the techniques of programming and problem solving, the specific syntax is easy to follow.Before the mid-1960s, computers were extremely expensive and used only for special-purpose tasks. A simple batch processing arrangement ran only a single "job" at a time, one after another. But during the 1960s faster and more affordable computers became available, and as prices decreased newer computer systems supported time-sharing, a system which allows multiple users or processes to use the CPU and memory. In such a system the operating system alternates between running processes, giving each one running time on the CPU before switching to another. The machines had become fast enough that most users could feel they had the machine all to themselves.
By this point the problem of interacting with the computer was a concern. In the batch processing model, users never interacted with the machine directly, instead they tendered their jobs to the computer operators. Under the time-sharing model the users were given individual computer terminals and interacted directly. The need for a system to simplify this experience, from command line interpreters to programming languages was an area of intense research during the 1960s and 70s.

Origin

The original BASIC language was designed in 1964 by John Kemeny and Thomas Kurtz and implemented by a team of Dartmouth students under their direction. The acronym is tied to the name of an unpublished paper by Thomas Kurtz and is not a backronym. BASIC was designed to allow students to write programs for the Dartmouth Time-Sharing System. It was intended specifically for the new class of users that time-sharing systems allowed—that is, a less technical user who did not have the mathematical background of the more traditional users and was not interested in acquiring it. Being able to use a computer to support teaching and research was quite novel at the time.
The language was based on FORTRAN II, with some influences from ALGOL 60 and with additions to make it suitable for timesharing. Initially, BASIC concentrated on supporting straightforward mathematical work, with matrix arithmetic support from its initial implementation as a batch language and full string functionality being added by 1965.
The designers of the language decided to make the compiler available free of charge so that the language would become widespread. They also made it available to high schools in the Hanover area and put a considerable amount of effort into promoting the language. In the following years, as other dialects of BASIC appeared, Kemeny and Kurtz's original BASIC dialect became known as Dartmouth BASIC.

Significant Language Features
Basic is a multi-platform language because many basic compilers use the same types of routines. Basic allows:
  • Loops
  • Input from the keyboard
  • Menu Driven Applications
  • System Commands - These are words that make the system perform a specific task immediately.
  • Structured Programming
  • Subroutines
  • Built-In Functions
  • User-Defined Functions
  • Arrays, sorting, and searches


Areas of Application
Basic has many strong points, such as:
  • Easy to learn for beginners
  • Adds powerful additional features for the advanced user
  • Is designed for interactive use rather than batch work
  • Lends itself to learning by hands-on practical use
and is therefore suitable for both the professional and non-professional.

Syntax in BASIC Programming Language


The Basic Programming Language

Typical BASIC keywords

Data manipulation
  • LET: assigns a value (which may be the result of an expression) to a variable.
  • DATA: holds a list of values which are assigned sequentially using the READ command.
Program flow control
  • IF ... THEN ... ELSE: used to perform comparisons or make decisions.
  • FOR ... TO ... {STEP} ... NEXT: repeat a section of code a given number of times. A variable that acts as a counter is available within the loop.
  • WHILE ... WEND and REPEAT ... UNTIL: repeat a section of code while the specified condition is true. The condition may be evaluated before each iteration of the loop, or after.
  • DO ... LOOP {WHILE} or {UNTIL}: repeat a section of code Forever or While/Until the specified condition is true . The condition may be evaluated before each iteration of the loop, or after.
  • GOTO: jumps to a numbered or labelled line in the program.
  • GOSUB: temporarily jumps to a numbered or labelled line, returning to the following line after encountering the RETURN Command. This is used to implement subroutines.
  • ON ... GOTO/GOSUB: chooses where to jump based on the specified conditions. See Switch statement for other forms.
Input and output
  • PRINT: displays a message on the screen or other output device.
  • INPUT: asks the user to enter the value of a variable. The statement may include a prompt message.
  • TAB or AT: sets the position where the next character will be shown on the screen or printed on paper.
Miscellaneous
  • REM: holds a programmer's comment or REMark; often used to give a title to the program and to help identify the purpose of a given section of code.
  • USR: transfers program control to a machine language subroutine, usually entered as an alphanumeric string or in a list of DATA statements.

Data types and variables

Minimal versions of BASIC had only integer variables and one-letter variable names. More powerful versions had floating-point arithmetic, and variables could be labelled with names six or more characters long.
String variables are usually distinguished in many microcomputer dialects by having $ suffixed to their name, and string values are typically enclosed in quotation marks.
Arrays in BASIC could contain integers, floating point or string variables.
Some dialects of BASIC supported matrices and matrix operations, useful for the solution of sets of simultaneous linear algebraic equations. These dialects would support matrix operations such as assignment, addition, multiplication (of compatible matrix types), and evaluation of a determinant. Microcomputer dialects often lacked this data type and required a programmer to provide subroutines to carry out equvalent operations.

Examples

The original Dartmouth Basic was unusual in having a matrix keyword, MAT. Although dropped by most later microprocessor derivatives it is used in this example from the 1968 manual which averages the numbers that are input:
5 LET S = 0
10 MAT INPUT V
20 LET N = NUM
30 IF N = 0 THEN 99
40 FOR I = 1 TO N
45 LET S = S + V(I)
50 NEXT I
60 PRINT S/N
70 GO TO 5
99 END
New BASIC programmers on a home computer might start with a simple program similar to the Hello world program made famous by Kernighan and Ritchie.
10 PRINT "Hello, World!"
140 END
This generally involves simple use of the language's PRINT statement to display the message (such as the programmer's name) to the screen. Often an infinite loop was used to fill the display with the message.
Most first generation BASIC languages such as MSX BASIC and GW-BASIC supported simple data types, loop cycles and arrays. The following example is written for GW-BASIC, but will work in most versions of BASIC with minimal changes:
10 INPUT "What is your name: ", U$
20 PRINT "Hello "; U$
30 INPUT "How many stars do you want: ", N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "Do you want more stars? ", A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "Goodbye "; U$
140 END
The resulting dialog might resemble:
What is your name: Mike
Hello Mike
How many stars do you want: 7
*******
Do you want more stars? yes
How many stars do you want: 3
***
Do you want more stars? no
Goodbye Mike
Second generation BASICs (for example QuickBASIC and PowerBASIC) introduced a number of features into the language, primarily related to structured and procedure-oriented programming. Usually, line numbering is omitted from the language and replaced with labels (for GOTO) and procedures to encourage easier and more flexible design.
INPUT "What is your name: ", UserName$
PRINT "Hello "; UserName$
DO
  INPUT "How many stars do you want: ", NumStars
  Stars$ = STRING$(NumStars, "*")
  PRINT Stars$
  DO
    INPUT "Do you want more stars? ", Answer$
  LOOP UNTIL Answer$ <> ""
  Answer$ = LEFT$(Answer$, 1)
LOOP WHILE UCASE$(Answer$) = "Y"
PRINT "Goodbye "; UserName$
Third generation BASIC dialects such as Visual Basic, REALbasic, StarOffice Basic and BlitzMax introduced features to support object-oriented and event-driven programming paradigm. Most built-in procedures and functions are now represented as methods of standard objects rather than operators.
The following example is in Visual Basic .NET:
Public Class StarsProgram
    Public Shared Sub Main()
        Dim UserName, Answer, stars As String, NumStars As Integer
        Console.Write("What is your name: ")
        UserName = Console.ReadLine()
        Console.WriteLine("Hello {0}", UserName)
        Do
            Console.Write("How many stars do you want: ")
            NumStars = CInt(Console.ReadLine())
            stars = New String("*", NumStars)
            Console.WriteLine(stars)
            Do
                Console.Write("Do you want more stars? ")
                Answer = Console.ReadLine()
            Loop Until Answer <> ""
            Answer = Answer.Substring(0, 1)
        Loop While Answer.ToUpper() = "Y"
        Console.WriteLine("Goodbye {0}", UserName)
    End Sub
End Class

Example codes in BASIC Programming Language


The Basic Programming Language

Hello World Example program

Description
This program prints the phrase "Hello World" infinitely.


Source Code
10 PRINT "Hello World!"
20 GOTO 10



Sample Run
Hello World!
Hello World!
Hello World!  etc., etc....




Arithmetic Operations Example Program

Description
This program performs basic arithmetic operations.


Source Code
10 INPUT "ENTER TWO NUMBERS SEPARATED BY A COMMA:
20 LET S = N1 + N2
30 LET D = N1 - N2
40 LET P = N1 * N2
50 LET Q = N1 / N2
60 PRINT "THE SUM IS ", S
70 PRINT "THE DIFFERENCE IS ", D
80 PRINT "THE PRODUCT IS ", P
90 PRINT "THE QUOTIENT IS ", Q
100 END


Sample Run
ENTER TWO NUMBERS SEPARATED BY A COMMA:
4 2
THE SUM IS 6
THE DIFFERENCE IS 2
THE PRODUCT IS 8
THE QUOTIENT IS 2







Example Screenshot of BASIC Programming Language



The Basic Programming Language

The IDE (fully written in PureBasic) on Windows, Linux and MacOS X:
 

Windows

Linux

MacOS X


  Some applications and games written in PureBasic:
 

CPU Graph

Restricted Area

Blue Ballonz

Bytessence Installer

B-Intruder 2

Database Scanner

Elementary Reports

Guild War Tactics

Hoverbots

i2pdf

Internet TV

Lethal Judgment 4

PureBreaker 3

PicAsmEditor

Post-it

ReportPlus

Restaurant POS

SoftRescue

Transpetris

Pyrex

SmartPacker

Nova Attractor

Magical Twilight

3D Nuclear Fusion

MemPad

GreenForce Player

XMas Survivor

ip2c

AVR-NET-IO

OliLPT32
visual basic compiler