For(T,R,A,N is an esoteric subset of the TI-BASIC programming language on the TI-83 series of graphing calculators created by User:Kg583, where
For( statements are one of the few TI-BASIC features permitted.
Because expressions more complicated than integer literals or single variables are not permitted, all computation must be performed with
For( statements, which can be used for control flow, variable assignment, addition, and multiplication.
For(T,R,A,N is named after the non-esoteric language Fortran. The name itself is also a valid For(T,R,A,N program, since TI-BASIC does not require
For( statements to have a closing
For(T,R,A,N only allows the following types of statement:
For(statements, which take the form
For(A,B,C, where A is the variable being iterated over, B is the starting value, C is the ending value, and D is the optional step amount, which defaults to 1.
Endstatements, which mark the end of the body of a
For(loop. If a loop does not have a corresponding
Endstatement, execution of the program stops once the end of the program is reached.
Dispstatements, which take the form
Disp A, where A is the value to output.
Each parameter used in a
Disp statement must be exactly one of the following:
- An integer literal.
- A real-number variable (e.g., the characters A-Z and θ).
Ansvariable, for accepting user input.
Newlines and colons (
:) are treated identically.
A variant of For(T,R,A,N allows the
Input statement but disallows
Disp and instead uses the initial and final states of the variables as input and output, respectively.
Execution of the
- The starting value (2nd parameter) is loaded into the iterator (1st parameter).
- The ending value (3rd parameter) and step (optional 4th parameter) are cached.
- If the sign of the cached step (value of the optional 4th parameter at the beginning of the loop, or 1) is negative and the iterator (1st parameter) is less than the cached ending value (value of the 3rd parameter at the beginning of the loop) OR the sign of the cached step is positive or zero and the iterator is greater than or equal the cached ending value, execution of the
For(loop ends and execution jumps to the matching
Endtoken, if it exists, or stops the program, if it doesn't.
- The body of the
For(loop is executed; commands are read and executed until the end of the program or a matching
Endtoken is found.
- If a matching
Endstatement is found, the cached step value (value of the optional 4th parameter at the beginning of the loop, or 1) is added to the current value of the iterator variable (1st parameter) and stored to the iterator variable.
- Steps 3-6 are repeated.
Notice that the iterator can be changed to any value during the execution of the loop, while the other parameters are locked at the beginning of execution.
Variable assignment - assigns the value 42 to A:
Addition - assigns A + B to C:
Multiplication - assigns A * B to C
For(C,0,-1:End For(X,1,A For(C,C,C,B:End End
Fibonacci number generator:
For(A,0,0:For(B,1,1 For(D,2,Ans For(C,A,A,B:End For(A,B,0:End For(B,C,0:End Disp B End
Prime number generator:
Disp 2 For(P,3,Ans,2 For(Q,P,P,-1:End For(D,3,Q,2 For(R,P,D,-D:End For(S,R,0 For(D,Q,Q,Q:End End End For(Q,Q,Q,Q:End For(S,D,Q Disp P For(S,Q,Q:End End End
Assigns the value of R to T, assuming N is non-zero:
Additional For(T,R,A,N code samples can be found here; contributions of programs are welcomed and appreciated.
As For(T,R,A,N is a subset of TI-BASIC, For(T,R,A,N programs can be run on any TI-83 series graphing calculator with no additional setup.
- The original Cemetech topic contains more information and several other example programs, as well as the basic components of a theoretical compiler.