Sunday, February 3, 2019

Calculator Programming: Making FOR, WHILE, and REPEAT Loops with IS>, DS<, GOTO, IF, LBL

Calculator Programming:  Making FOR, WHILE, and 
REPEAT Loops with IS>, DS<, GOTO, IF, LBL

Introduction

Say your programming capabilities on your calculator, BASIC portable computer, or programming app does not have the FOR, WHILE, and REPEAT loop structures.  No worries, there are some workarounds we can use.

Today the programs will be demonstrated with the language of the TI-81 and TI-84 Plus CE, but this blog isn't limited to these two calculators.


Simulating FOR Loops with IS> and DS<

The TI-81 (and every Texas Instruments graphing calculator of that family inclusive to the TI-84 Plus CE) has the commands IS> and DS<.

IS>:  Increment and Skip

Syntax:  IS>(variable, target number)

IS> increases the value stored in a variable by 1 and performs a comparison test.  The next command is excited if the increased value is less than or equal to the target number.

IS>(var, target)
[do this command if var + 1 ≤ target]
[skip to this command if var + 1 > target]

Simulating the FOR Loop:

FOR var = begin TO end*
[commands]
NEXT
[commands after loop is over]


* Syntax varies.  For the TI-84 Plus CE:  For(var,begin, end) : [commands] : End

with:

begin → var
LBL [label]
[commands]
IS>(var, end)
GOTO [label]
[commands after loop is over]

The program PRGM1 demonstrates how to accomplish a FOR loop with IS>.  PRGM1 displays the numbers 1 to 10.  The TI-81 section can be programmed by on the TI-81 and TI-84 Plus CE, which the TI-84+ section is for calculators TI-82 and later.

"TI-81"
1→K
Lbl 1
Disp K
IS>(K,10)
Goto 1
Disp "END"
Wait 2
"TI-84+"
For(K,1,10)
Disp K
End
Disp "END"

DS<   

Decrement and Skip

Syntax:  DS<(variable, target number)

DS< decreases the value stored in a variable by 1 and performs a comparison test.  The next command is excited if the increased value is greater than or equal to the target number.  DS< is the opposite of IS>.

DS<(var, target)
[do this command if var - 1 ≥ target]
[skip to this command if var - 1 < target]

Simulating the FOR Loop:

FOR var = begin TO end STEP -1*
[commands]
NEXT
[commands after loop is over]


* Syntax varies.  For the TI-82 to the TI-84 Plus CE, including TI-80 and TI-73:
For(var,begin, end, -1) [commands] End

with:

begin → var
LBL [label]
[commands]
DS<(var, end)
GOTO [label]
[commands after loop is over]

PRGM2 demonstrates the use of DS< and the associated For loop.


"TI-81"
10→K
Lbl 1
Disp K
DS<(K,1)
Goto 1
Disp "END"
Wait 2
"TI-84+"
For(K,10,1,­1)
Disp K
End
Disp "END"

Simulating WHILE and REPEAT Loops

With the proper use of the IF, LBL, and GOTO we can simulate WHILE and REPEAT loops.

Simulated WHILE Loops

WHILE [condition is true]
[commands]
END

* While is available for TI-82 to the TI-84 Plus CE, including TI-73.

can be simulated by:

LBL [label]
[commands]
IF [while condition] 
GOTO [label]

Simulated REPEAT Loops

REPEAT
[commands]
UNTIL [condition]

* The syntax for the TI-82 to the TI-84 Plus CE, including TI-73 is:
Repeat [condition] : [commands] : End

LBL [label]
[commands]
IF [inverse of the repeat condition] 
GOTO [label]

Example:  If the repeat condition is T>5, then the inverse is T≤5.

PRGM3 is a demonstration program on how all three techniques are used to accomplish this:

Start with 1000.  Take the square root.  Keep going until the calculator gets to 1 (by the precision of the calculator).

"TI-81"
1000→K
Lbl 1
√(K)→K
Disp K
If K≠1
Goto 1
Disp "END"
Wait 2
"84+ WHILE"
1000→K
While K≠1
√(K)→K
Disp K
End
Disp "END WHILE"
Wait 2
"84+ REPEAT"
1000→K
Repeat K=1
√(K)→K
Disp K
End
Disp "END REPEAT"

I hope you find these tips useful and helpful.

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...