Programming Commands

Every command on the calculator is useful for programming, but some are expressly designed for that purpose. These are roughly divided into three categories: commands to control the flow of a program, commands to manage variables, and commands that provide input and output.

Control Flow

Any program is just a sequence of commands; but usually, it's not enough to just run through them all one by one in order and be done. Changes to this order have to be made: some commands should only be followed in certain situations, others might be repeated several times, still others might be a last resort in case of an error. Control flow commands are those that determine this order.

The simplest control flow commands are Goto and Lbl, which simply involve jumping around in the program. This isn't always the best way of doing things, though, and there are many alternatives:

Conditionals

A common situation is when certain commands depend on a condition being met. The following commands address this situation:

  • The If statement simply places a condition on a command or block of commands.
  • The Else statement, used with If, provides an alternative branch if the condition is not met.
  • The ElseIf statement, also used with If, allows for several mutually exclusive conditions.

Conditions are typically created by combining equality relations (=, , >, , <, ) with logical operators (and, or, xor, not).

Loops

Loops allow commands to be repeated over and over. The following types of loops exist:

  • Loop..EndLoop blocks just keep repeating forever.
  • While..EndWhile blocks repeat as long as a condition is satisfied.
  • For..EndFor blocks repeat a fixed number of times.

To deal with these loops, we have a couple auxiliary commands:

  • Cycle prematurely goes back to the beginning of a loop.
  • Exit leaves a loop ahead of time.

Subroutines

If a task has to be done several times inside a program, the code for it can be removed to a subroutine: this routine can then be "called" whenever necessary. Subroutines in TI-Basic are essentially programs of their own. They can be defined inside a program with the Define command, and are of two types:

  • Functions (defined with Func..EndFunc) return a value, and can't affect the overall state of the calculator.
  • Programs (defined with Prgm..EndPrgm) can do anything, but don't return a value directly.

Two commands exist specifically for use with subroutines.

  • Return exits a subroutine, returning to the program that called it.
  • Stop exits every program currently running, subroutine or not.

Error Catching

Error catching provides a last resort if an error occurs. A portion of the program, or even the entire program itself, can be put into a Try..Else..EndTry block. The code after Else will only run in case of an error, and has the option to ClrErr — go on as though nothing happened — or PassErr — handle the error normally, with an OS error message.

Variable Management

Another part of programming is managing variables. This means:

There is also the Local command, which designates certain variables as local to the program they are used in.

Input and Output

Finally, a program has to be able to get input from the user and give some output in response. For games, this usually means using the graphics commands, and reading keys with the getKey() command. There are other alternatives, however.

On the Program I/O screen:

A more stylish method is to use dialogs, wrapped in a Dialog..EndDlog box.

  • Input here is accomplished with Request and DropDown.
  • The Text command, appropriately, displays text. A Title is also handy.

Some miscellaneous commands remain. Custom..EndCustm and Toolbar..EndTBar both create toolbar menus with the help of the Title and Item commands. And PopUp displays a popup menu.

Input and output also refers to interacting with other calculators. There are five commands for the purpose:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.