Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
FOCAL (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Commands === ====ASK==== The {{code|ASK}} command (abbreviation A) will take a list of strings and variables, echo the strings and store the user input in variables.{{sfn|Manual|1968|p=3.2}} Equivalent to BASIC's {{code|INPUT}}. 01.01 ASK "NAME", NAME 01.02 ASK "COORDINATES", X, Y 01.03 ASK "A1",A1,"OMEGA",W,"T0",T0,"DAMPING FACTOR",DAMPINGFACTOR If the user doesn't enter a number but enters text, the system will convert the initial character to a number with "A"=1, "B"=2, etc. ====COMMENT==== The {{code|COMMENT}} command (abbreviation C) creates a remark.{{sfn|Manual|1968|p=3.6}} Equivalent to BASIC's {{code|REM}}. The original manual lists {{code|CONTINUE}} as a synonym of COMMENT, used to mark empty lines, but this has no internal difference.{{sfn|Manual|1968|p=A.1}} 01.01 COMMENT: THE SUMER GAME, BY RICHARD MERRILL ====DO==== The {{code|DO}} command (abbreviation D) branches execution to a subroutine. It is the equivalent of BASIC's {{code|GOSUB}}. The subroutine is referenced either by group number or line number. If a line number is provided, that single line is run and then automatically returns to continue execution at the statement after the {{code|DO}}. If no line number is provided, execution starts at the first line of the block and continues until the end of the block is reached. {{code|RETURN}} is supported, but is only required to return early from the group, it is not needed at the end of the group.{{sfn|Manual|1968|p=3.4}} 01.15 DO 7.24 01.16 DO 8 ====FOR==== The {{code|FOR}} command (abbreviation F) implements a [[for loop]]. When three arguments are specified, the first is the initial value of the loop variable, the second is the increment, and the third value is the terminating value for the loop. If only two values are provided, the first is the initial value and the second is the terminating value, and the increment is set to 1. This is the pattern from [[FORTRAN]]'s {{code|DO}} loops, as opposed to BASIC's {{code|FOR}} where the increment is the last value, if present. In contrast to other parts of the language where multiple statements on a line are independent, the {{code|FOR}} always runs the statements that follow it on the line before the termination has been met, and then continues to the next line. Thus, loops have to be on a single line, or alternatively, call a subroutine with {{code|DO}}. There is no equivalent of BASIC's {{code|NEXT}}.{{sfn|Manual|1968|p=3.7}} 01.01 FOR X=1,10; TYPE X,! 01.02 FOR X=0,10,100; DO 2 A sample FOR loop: 01.10 ASK "HOW MUCH MONEY DO YOU WANT TO BORROW ?",PRINCIPAL 01.20 ASK "FOR HOW MANY YEARS ?",TERM 01.30 FOR RATE=4.0,.5,10;DO 2.0 01.40 QUIT 02.10 SET INTEREST=PRINCIPAL*(RATE/100)*TERM 02.20 TYPE "RATE",RATE," ","INTEREST",INTEREST,! ====GOTO==== The {{code|GOTO}} command (abbreviation G) jumps program execution to the specified line number.{{sfn|Manual|1968|p=3.4}} It is identical to the same-named statement in BASIC. In FOCAL, {{code|GOTO}} is also used to begin execution, like BASIC's {{code|RUN}}, but in this use, the documentation refers to it as {{code|GO}} instead of {{code|GOTO}} in spite of the underlying command being the same. 01.05 GOTO 1.01 02.90 TYPE !!,"TRY AGAIN.",!!!!!;GOTO 1.1 ====IF==== The {{code|IF}} command (abbreviation I) provides a conditional branch based on the sign of the expression. After the numeric expression, the IF command can take one to three line numbers. If the expression is less than zero, execution branches to the first line number; if equal to zero, to the second line number; if greater than zero, to the third line number. The language lacked relative operators such as greater than, equal or less than. To branch if X > 5, one must compare X - 5.{{sfn|Manual|1968|p=3.5}} 02.20 IF (25-25) 2.4,2.3,2.4 03.01 IF (X) 3.1,3.02,3.1 IF could be short-formed by placing a semicolon (or end of line) beyond the first line number. For example: 02.20 IF (X)1.8; TYPE "Q" 02.30 IF (X)1.8,2.50 02.40 TYPE "P" In this case the test at 2.20 will cause the program to jump to line 1.8 if the test is negative, otherwise it will continue and type "Q" to the console. Line 2.30 will jump to 1.8 or 2.5 if the value is negative or zero, and otherwise continue to type "P" to the console.{{sfn|Manual|1968|p=3.5}} ====QUIT==== The {{code|QUIT}} command (abbreviation Q) terminates execution of the program and returns control to the editing environment.{{sfn|Manual|1968|p=3.6}} Equivalent to BASIC's {{code|STOP}} or {{code|END}}. 01.10 FOR X=-10,1,10;TYPE X 01.20 QUIT ====RETURN==== The {{code|RETURN}} command (abbreviation R) branches execution from a subroutine back to the calling location.{{sfn|Manual|1968|p=3.6}} The use of {{code|RETURN}} is optional at the last line of a subroutine, a subroutine returns at the last line in the group anyway. The following is a sample subroutine for converting a yes/no prompt into a value.[http://www.pdp8.net/lang/focal/misc.shtml] 22.78 COMMENT: 'YES OR NO' SUBROUTINE 22.80 ASK "ANSWER YES OR NO ? ",AN 22.82 IF (AN-0YES)22.84,22.86 22.84 IF (AN-0NO)22.8,22.88,22.8 22.86 SET X=2;RETURN 22.88 SET X=1;RETURN ====SET==== The {{code|SET}} command (abbreviation S) assigns the results of an expression to the specified variable.{{sfn|Manual|1968|p=3.3}} Equivalent to BASIC's {{code|LET}}. 01.30 SET PI=3.14156 01.60 SET INTEREST=PRINCIPAL*(RATE/100)*TERM ====TYPE ==== The {{code|TYPE}} command (abbreviation T) provides for output of one or more items separated by commas.{{sfn|Manual|1968|p=3.1}} Equivalent to BASIC's {{code|PRINT}}. Items can be variables, literal strings surrounded by double-quotes, or a variety of control characters. The control characters include the {{code|!}} to output a carriage return and line feed, {{code|#}} for the carriage return alone, and {{code|:}} for a tab character. Control characters can be strung together, for example, {{code|!!!}} will output three CR/LFs without the need to separate them with commas.{{sfn|Manual|1968|p=3.2}} TYPE [NUMBERS, E1, "TEXT", !, #, :, $ OR %] ...OUTPUT 01.10 TYPE "HI THERE, GOOD LOOKING. HOW MUCH MONEY DO YOU WANT TO BORROW?",! 01.50 TYPE "INTEREST",INTEREST,! 01.80 TYPE "THE INTEREST FOR",TERM," YEARS",!,"IS",INTEREST, " DOLLARS.",!! 01.90 TYPE "NEW YORK",!,"WASHINGTON",!,"ATLANTA",!,"DALLAS",! 02.10 TYPE "X",X," ","X^2",X^2," ","SQRT",FSQT(X) 03.20 TYPE ".",# 02.20 TYPE !!!!! {{code|TYPE}} also included an optional format specifier indicated using the format {{code|%x.yz}}, where x is the number of digits to the left of the decimal, and yz is the number of digits to the right of the period. The default format was {{code|%8.4}}, meaning a maximum of eight digits and four to the right of the period.{{sfn|Manual|1968|p=2.2}} So, for example: SET A=67823 TYPE %6.01,A = 67823.0 TYPE %5,A = 67823 TYPE %8.03,A = 67823.000 TYPE %,A = 6.7823E4 Note the extra leading spaces in some examples, padding out the full defined width. Using % alone caused the output to be printed in "floating point format" using the E.{{sfn|Manual|1968|p=2.3}} A special control character was {{code|$}} which caused a table of all defined variables and their values to be printed. Only the first two letters of the name will be printed, padded with a zero if need be. Arrays elements are printed on separate lines and variables with only one element will be indexed (00). For example:{{sfn|Manual|1968|p=2.5}} TYPE $ A0(00)=67823
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)