From Esolang
Jump to navigation Jump to search

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.


For(T,R,A,N only allows the following types of statement:

  • For( statements, which take the form For(A,B,C,D or 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.
  • End statements, which mark the end of the body of a For( loop. If a loop does not have a corresponding End statement, execution of the program stops once the end of the program is reached.
  • Disp statements, 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 Ans variable, 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

  1. The starting value (2nd parameter) is loaded into the iterator (1st parameter).
  2. The ending value (3rd parameter) and step (optional 4th parameter) are cached.
  3. 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 End token, if it exists, or stops the program, if it doesn't.
  4. The body of the For( loop is executed; commands are read and executed until the end of the program or a matching End token is found.
  5. If a matching End statement 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.
  6. 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


Fibonacci number generator:

Disp B

Prime number generator:

Disp 2
Disp P

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.

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.