User:PauliKL/ANSI BASIC
ANSI BASIC is the standard published by the American National Standards Institute (ANSI) for the BASIC programming language. There are two standards: ANSI X3.60-1978 Minimal Basic and ANSI X3.113-1987 "Full Basic". These standards were subsequently adopted by International Organization for Standardization (ISO).
History
[edit]ANSI Minimal Basic
[edit]ANSI Full Basic
[edit]The Proposed Standard for Basic was published in the year 1983 [1].
Language constructs
[edit]Hello world
[edit]Unlike most other languages, typical BASIC implementations do not require any decorative constructs in the program. In ANSI BASIC, however, END instruction is mandatory.
BASIC does not need semicolons or similar to mark end of statement. Each statement ends at the end of line, unless line continuation character '\' is used. Unlike most real world Basic implementations, ANSI BASIC still requires line numbers.
Here is an example source code for a very simple Hello world program:
10 PRINT "Hello, World" 20 END
Control structures
[edit]ANSI BASIC is a structured programming language.[2] Some of the basic control structures are described below.
Conditional statements:
10 IF a > b THEN 20 b = b*2 30 sum = sum + a 40 ELSE 50 a = a+1 60 sum = sum + b 70 END IF 100 SELECT CASE value 110 CASE 1 120 CALL do_something 130 CASE 2,3,4 140 CALL do_otherthing(value) 150 CASE IS > 4 150 counter = counter+1 160 value = value/2 170 CASE ELSE 180 PRINT "Incorrect value" 190 END SELECT
Loops
The DO...LOOP structure by itself creates an endless loop. However, it may have an exit statement WHILE or UNTIL at the beginning and/or at the end. In addition, EXIT DO statement can be used to exit anywhere in the middle of the loop.[3]
200 DO 210 PRINT question$ 220 INPUT answer$ 230 IF answer = "quit" THEN EXIT DO 240 CALL check_answer(answer$) 220 LOOP WHILE time_left
FOR...NEXT loop may have an optional step value. Exit from middle of the loop can be done with EXIT FOR.
300 FOR row = 1 TO maxrows 310 FOR column = 1 TO maxcols STEP 8 320 PRINT TAB(column);"*"; 330 NEXT column 340 PRINT 350 NEXT row
Procedures and functions
[edit]ANSI BASIC has two types of procedures: SUBs and FUNCTIONs. The difference is that a FUNCTION returns a value, SUB does not. Both of them can be either internal or external. In internal procedure, all the variables are global within the program unit. In external procedure, all variables are local.[4]
500 SUB check_answer(answer$) 510 IF answer$ = correct$ THEN 520 PRINT "Correct!" 530 score = score+1 540 CALL NextQuestion 550 ELSE 560 PRINT "Wrong, try again." 570 ENDIF 580 END SUB
References
[edit]- ^ Harle, James (May 1983). "The Proposed Standard for Basic". ACM SIGPLAN Notices.
{{cite web}}
: CS1 maint: date and year (link) - ^ Gordon, Alan M. (1985). Super Programmer - Professional programming in ANSI Standard BASIC. Sigma Press. ISBN 1-85058-002-2.
- ^ Luehrmann, Arthur (October 1984), "Structured programming in Basic; part 5: control structures in ANSI Basic.", Creative Computing, 10 (10): 131
{{citation}}
: CS1 maint: date and year (link) - ^ Luehrmann, Arthur (September 1984). "Structured programming in Basic; part 4: ANSI Basic, Macintosh Basic, and True Basic". Creative Computing. 10 (9): 171. Retrieved 2010-10-23.