Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I was programming a Quadratics Program in TI-BASIC, and it would do its thing, but I wanted a way let the person rerun the program without having to reselect it. This is what I did instead:

Code:

Pause
PrgmQUAD

(PS: The name of my program was "QUAD"
any better way of a program loop?
If the person continues to run the program enough they will eventually encounter an ERR:MEMORY because of calling the program from within itself, and then that run of the program calling itself again, etc. It'd be better to put a label at the start of the program and use a Goto at the end.

EDIT: Note that if you're interested in speed it might be better to use one of these loops instead, but I assume that you might not be that worried about it with a math program

Code:

While 1

(Your program code goes here)

End
I would expect speed to only be an issue if you're running a tight loop many times a second. If you're just having the user enter some values, do calculations, printing the result, and then repeating, the speed difference between Lbl:Goto and one of the "more proper" looping structures to jump from printing results back to requesting more input should be completely negligible, even in TI-BASIC.
Here's a quick example (and something I use on my math progs)

Code:
Lbl A
(code)
Disp "result","Press [+] to exit, [ENTER] to go again."
Repeat K=95 or K=105
getKey->K
End
If K=95:Goto A
willwac wrote:
Here's a quick example (and something I use on my math progs)

Code:
Lbl A
(code)
Disp "result","Press [+] to exit, [ENTER] to go again."
Repeat K=95 or K=105
getKey->K
End
If K=95:Goto A


That works quite well, but here is one to just avoid the goto function entirely:


Code:

Repeat K=95
(code)
Disp "result","Press [+] to exit, [ENTER] to go again."
Repeat K=95 or K=105
getKey->K
End:End

Code:
Repeat K=95
(code)
Disp "result","Press [+] to exit, [ENTER] to go again." 
Repeat K>94
getKey->K 
End:End

Smile

Code:

Repeat Ans=95
(code)
Disp "result","Press [+] to exit, [ENTER] to go again." 
Repeat Ans>94
getKey
End:End

Smile

Code:

Repeat Ans=95
(code)
Disp "result","Press [+] to exit, [ENTER] to go again.
Repeat Ans>94
getKey
End:End


Believe the end quote there is unnecessary, yes?
turiqwalrus wrote:

Code:

Repeat Ans=95
(code)
Disp "result","Press [+] to exit, [ENTER] to go again.
Repeat Ans>94
getKey
End:End


Believe the end quote there is unnecessary, yes?


So true! By the way, will this long string fit?
MateoConLechuga wrote:
turiqwalrus wrote:

Code:

Repeat Ans=95
(code)
Disp "result","Press [+] to exit, [ENTER] to go again.
Repeat Ans>94
getKey
End:End


Believe the end quote there is unnecessary, yes?


So true! By the way, will this long string fit?


16 charecters per screen. this does indeed cause the text to go off. perhaps we should use an Output( and get text looping?
I've had this topic sitting open in a tab in my browser for nearly two months now, so it's time to be done with it. I just wanted to interject that recursion is probably the worst (read: slowest and most memory-intensive) way to loop (yes, I'm looking at you, Haskell). As the people in this topic have indicated, you have tons of other options, ranked from least appropriate to most appropriate:
1: Lbl and Goto: While this works for loops, it is discouraged. You should use Lbl and Goto for jumping between large sections of your program if you must, but not for tight loops. It is not memory-intensive, but it is slow, and it gets slower the further down in your program the target Lbl is.
2: For: In the particular case you mention, For() doesn't make much sense, because it is primarily used for loops with fixed numbers of iterations.
3: While: While would be a good choice, but you'd need slightly more code to initialize the escape condition before the first run. For example:
Code:
:1->C:While C
:<run code>
:Input "AGAIN (1=YES, 0=NO)", C
:End
4: Repeat: This would be the most appropriate choice, as the loop will always run at least once regardless of the condition:
Code:
Repeat C
:<run code>
:Input "AGAIN (1=YES, 0=NO)", C
:End


Good luck.
KermMartian wrote:
I've had this topic sitting open in a tab in my browser for nearly two months now, so it's time to be done with it. I just wanted to interject that recursion is probably the worst (read: slowest and most memory-intensive) way to loop (yes, I'm looking at you, Haskell).

This isn't strictly true across the board, but it certainly applies here.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement