Texas Instruments TI-73 Car Stereo System User Manual


 
Chapter 12: Programming
231
7312ENG.DOC CH 12 Programming, English Julie Hewlett Revised: 07/29/98 12:17 PM Printed: 05/19/99 9:02
AM Page 231 of 32
Write a program named
TESTELSE
that tests an input value, X.
If X<0, then square it and store it to Y. If X0, then store it to
Y. Display X and Y.
PROGRAM:TESTELSE
:Input "X=",X
:If X<0
:Then
:X
"
Y
:Else
:X
"
Y
:End
:Disp {X,Y}
:Pause
For( For( 8
4 4
Use
For(
to control how many times a loop is repeated. A
For(
command loops to repeat the same group of commands
(block) and increments to control the number of times the loop
is repeated.
It executes commands in block through end, increasing
variable from begin by increment until variable>end.
increment is optional (default=1) and can be negative
(end<begin). end is a maximum or minimum value not to be
exceeded, which identifies the end of the loop.
End
identifies
the end of block. When variable>end, the program executes
each command following
End
.
For(
loops can be nested.
:For(
variable,begin,end[,increment]
)
:
block (while variable { end)
:End
:
command
Write a program named
SQUARE
that displays A
2
, where
0=begin, 8 =end, and 2=increment.
PROGRAM:SQUARE
:For(A,0,8,2)
:Disp A
:Pause
:End
³
³
Press
b
between results.