Jump to content

TI-Basic 84 Programming/Recursion

From Wikibooks, open books for an open world

Recursion in programs involves calling up the program to run again from the beginning. If not done carefully it can create infinite loops of code that won't terminate. If you run a program that gets stuck in a loop you can press the On button; the On button terminates execution of any program.

How to do it

[edit | edit source]

Writing code that does is simple, within the program you simply have a call to the current program. The syntax is PRGM:EXEC then whatever program.

PROGRAM:TEMP
://code
://code
:prgmTEMP

If you use recursion you always want to have some condition that has to be met in order for the recursive call to happen. An easy way to do this is to encapsulate the recursive call in an "If" statement or a while loop.

Example

[edit | edit source]

In this example we will write a simple counting program. Before we run this program we have to set X to a number, for this example we will assume it has been set to 0.

PROGRAM:COUNT
While X≤3
Disp X
X+1->X
prgmCOUNT

(Note: End is not needed here since the while already loops)

prgmCOUNT
       0
       1
       2
       3


Previous: Graph Databases
Table of Contents: TI-Basic 84 Programming