Introduction
TI-BASIC is the built-in program language that comes with the TI-83/84+ calculators
Optional Resources
1. TI-83 Plus Flash Debugger -> for running programs
2. TI Graph link -> For writing & saving programs
-or-
a TI-83/84 Plus calculator -> writes and runs programs
Loops
Loops are groups of code that run until a condition is met.
Ti-BASIC loops can be created 3 different ways:
First, there are While and Repeat loops
Secondly, there are For( loops
and Lastly, Lbl loops.
While:
If the condition is met, it runs the code between the While and the End until the condition is false.
For example:
Repeat:Code::0→X :While X<5 :X+1→X :Output(1,X,"V" :End Outputs: VVVVV
If the condition is NOT met, it runs the code between the While and the End until the condition is TRUE.
For example:
You can think of Repeat as Repeat Until <condition>Code::0→X :Repeat X<5 :X+1→X :Output(1,X,"V" :End Outputs:
For(:
For( is one of the more useful loop variations.
Syntax For(<var>, START, END, INC
So to generate the same output as the While loop above,
As you can see, using For( can really save some space and makes code look nicer.Code::For(X,1,5,1 :Output(1,X,"V" :End Outputs: VVVVV
NOTE: If you leave off the last argument, the INC defaults to 1. The code will also run faster with the last argument omitted
Lbl:
Most beginners at TI-BASIC tend to use Lbl loops because they make more sense to them. Experienced user do not. One reason is that when going to a label from inside a <insert command here> ... End statement, a memory leak occurs, which reduces the available memory by around 7 bytes (which is a lot in TI-BASIC!) Another reason Lbls are avoided is because they are slow.
To create a label loop:
Challenge Question Answer:Code::0→X :Lbl ST :X+1→X :Output(1,X,"V" :If X=5 :Goto ED :Goto ST :Lbl ED Outputs: VVVVV
Code:prgmGUESSING :25→X :While X≠A :Input A, "Guess Number: " :If A=X :Then :Disp "That's Right!" :Else :If A>X :Disp "Too High!" :If A<X :Disp "Too Low!" :End :End
Good job. +rep
Nice tutorial! +rep
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks