TI-BASIC/Loops

From Wikiversity
Jump to navigation Jump to search
PROGRAM:TEST
:1→X
:While 1
:While X<E10
:2X→X
:Disp X
:End
:While X>E-10
:.5X→X
:Disp X
:End
:End
→ is on the buttonpad as sto>
While & End can be found in the program menu
< & > can be found in TEST (above MATH)
!; to stop this function press ON, which is the emergency break for any program on the TI.

Loops[edit | edit source]

Loops are features in programs that tell it to repeat a certain number of commands over and over, for as often as you tell it to. The above program will use X (which starts off at 1) and will double it continuously until it reaches 1.7*1010, at which point the While logic says it isn't true and will skip to the other While until that is disproven as well.

why does While 1 keep repeating? time for an exercise with logic

Logic[edit | edit source]

Logic is what the calculator uses to understand when conditions are right. If 1=1 is typed on the regular calculating screen, the calculator will awnser with 1, telling you you're right 1 is equal to 1. If you were to type 3<2 it would tell you 0, which is it saying 3 isn't smaller than 2, that doesn't make sense. When While 2X<E10 is calculated, While is either 1 or 0, telling it to continue or skip. When While 1 is entered, it tells the program While is always true, due to the way the language was written (see [| assembly programming].)

PROGRAM:NAME
:2→H
:1→K
:If K=1
:Disp "YUP"
:If K>1
:Then
:Disp "NOPE"
:Else
:If H=2
:Then
:Disp "MHM"
:Else
:Disp "COOL"
:End
:End

If, Then and Else can all be found in the CTL list of the program menu. They all serve as a conditional clause, that inhibit some commands to be run, and enables them only if the condition proves true. In this example, If K=1 asks about K, but because it doesn't have Then following it, so (inclusively to TI-basic) it only proves the next line true.
This example also has a condition within a condition. Within Else and End it conditions for H, and it had to be ended before the If ended, otherwise it doesn't know when the inbound condition ends and simply skips it.

For(A,1,100,5[edit | edit source]

For is another loop, where increments are taken for every time it is run.

PROGRAM:TEST
:For(A,1,100,5
:Disp A
:End

will run and display A for every time from 1 to 100 with increments of 5;

1
6
11
16
21
26
...

For can be very useful when all values for a certain length have to be run through. example;

PROGRAM:NAME
:For(A,1,8
:For(B,1,16
:Output(A,B,"H"
:End
:End

=

HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH

back | next