Using loops to repeat a group of commands, F2] control toolbar menu, For...endfor loops – Texas Instruments PLUS TI-89 User Manual

Page 314

Advertising
background image

Chapter 17: Programming 297

17PROGRM.DOC TI-89/TI-92 Plus: Programming (English) Susan Gullord Revised: 02/23/01 1:14 PM Printed: 02/23/01 2:18 PM Page 297 of 40

To enter most of the loop-related
commands, use the Program
Editor’s „

Control

toolbar menu.

When you select a loop, the loop
command and its corresponding

End

command are inserted at the

cursor location.

:For |
:EndFor

You can then begin entering the commands that will be executed in
the loop.

A

For...EndFor

loop uses a counter to control the number of times

the loop is repeated. The syntax of the

For

command is:

For(

variable

,

begin

,

end

[,

increment

])

When

For

is executed, the variable value is compared to the end

value. If variable does not exceed end, the loop is executed;
otherwise, program control jumps to the command following

EndFor

.

:For i,0,5,1
: --------
: --------
:EndFor
:--------

At the end of the loop (

EndFor

), program control jumps back to the

For

command, where variable is incremented and compared to end.

Using Loops to Repeat a Group of Commands

To repeat the same group of commands successively, use a
loop. Several types of loops are available. Each type gives you
a different way to exit the loop, based on a conditional test.

Control Toolbar

Menu

Note: A loop command
marks the start of the loop.
The corresponding End
command marks the end of
the loop.

For...EndFor Loops

Note: The ending value can
be less than the beginning
value, but the increment
must be negative.

Note: The For command
automatically increments the
counter variable so that the
program can exit the loop
after a certain number of
repetitions.

added to the counter each subsequent time
For is executed (If this optional value is
omitted, the increment is 1.)

exits the loop when

variable exceeds this value

counter value used the first time For is executed

variable used as a counter

If the loop requires
arguments, the cursor is
positioned after the command.

i



5

i > 5

Advertising
This manual is related to the following products: