For(T,R,A,N
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 End statement.
Syntax
For(T,R,A,N only allows the following types of statement:
- For(statements, which take the form- For(A,B,C,Dor- 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 For( or Disp  statement must be exactly one of the following:
- An integer literal.
- A real-number variable (e.g., the characters A-Z and θ).
- The 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 Ans.
Another disallows Input  and Disp  and instead uses the initial and final states of the variables as input and output, respectively.
Execution of the For( loop
- 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 matchingEndtoken, 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 matchingEndtoken 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.
Examples
Assignment
Assigns the value 42 to A:
For(A,42,0:End
Assigns the value of R to T, assuming N is non-zero:
For(T,R,A,N
Addition
Assigns A + B to C:
For(C,A,A,B:End
Multiplication
Assigns A * B to C
For(C,0,-1:End For(X,1,A For(C,C,C,B:End End
Fibonacci
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 Numbers
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
Miscellany
Additional For(T,R,A,N code samples can be found here; contributions of programs are welcomed and appreciated.
Implementations
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.
There is also an online For(T,R,A,N interpreter written in JavaScript.
External resources
- The original Cemetech topic contains more information and several other example programs, as well as the basic components of a theoretical compiler.