A program I am making is running very slowly on my CSE. It is called prgmA. What am I doing wrong in the While loop?


Code:
ClrHome
Output(1,7,"|   |   |   |   |"
det(12,Black,Blue
Output(1,8," A "
det(12,Black,Magenta
Output(1,12," B "
det(12,Black,Green
Output(1,16," C "
det(12,Black,Orange
Output(1,20," D "
det(12,300
Output(2,1,"det(12,   ,   ,   ,   )"
0->A:0->B:255->C:255->D
Output(2,8,A
Output(2,12,B
Output(2,16,C
Output(2,20,D
Output(8,1,"Foreground  ||  Background"
Output(9,1,"--------------------------
Output(10,1,"    |    |      |    |    "
det(12,Black,Blue
Output(10,1," +1 "
det(12,Black,Magenta
Output(10,6," +1 "
det(12,Black,Red
Output(10,11," Quit "
det(12,Black,Green
Output(10,18," +1 "
det(12,Black,Orange
Output(10,23," +1 "


While getKey!=13
If getKey=11
A+1->A
If getKey=12
B+1->B
If getKey=14
C+1->C
If getKey=15
D+1->D

det(12,300
Output(2,8,A
Output(2,12,B
Output(2,16,C
Output(2,20,D
det(12,A,B,C,D
Output(4,1,"Your text"
End
ClrHome
Output(6,1,"Your text color"
det(12,300
Disp "A=","B=","C=","D="
Output(1,3,A
Output(2,3,B
Output(3,3,C
Output(4,3,D
Pause
I've run into this every now and then; using getKey as a loop condition slows the loop down drastically for some reason. Remove that and it should run faster -- although there's a better way to do the whole thing. Have you looked into using piecewise expressions? They're basically shorthand If statements, and using them you can optimize the key-input thing down to:

Code:

Repeat K=13 //replaced While with Repeat just in case K already equals 13
getKey->K
A+(Ans=11->A
B+(K=12->B
C+(K=14->C
D+(K=15->D

//output code here
End


As Electromagnet mentioned in SAX, you could alternatively 'pause' the program until the user presses a key, which is probably a better way of doing it.

Code:

Repeat K=13
Repeat Ans //same as Repeat Ans!=0
getKey
End
Ans->K

A+(Ans=11->A
B+(K=12->B
C+(K=14->C
D+(K=15->D

//output code here
End


sorry if these aren't as efficient as they could/should be, I'm pretty tired right now. This should give you the general idea, though!
This is my final code. It works exactly the way I want it to, and I am ready to put it into the archives. Because M. I. Wright helped me with a portion of the code, which I modified slightly as I got more ideas, will I put him as Co-author 1? Thanks!


Code:
:DCS
"4444444444444444443344333443334444343434444434444434343334443444443434344444344444334433344434444444444444444444999999999999999999996999996669999966699996999699999969999699969999996999999969999999699999969999999969999969999999666669966666999999999999999999
If 80>det([[20:Then:Disp "Get Doors CSE to run this:","http://dcs.cemetech.net":Return:End
ClrHome
real(0,1,1
real(0,3,4,151,1
real(0,3,4,151,1
real(0,1,0,0
"Low  High"
real(6,0,30,8,0,60,1
"Low  Hig"
real(6,0,95,8,0,60,1
"h
real(6,0,0,8,0,60,1
det(12,0,0,151,151
Output(1,7,"|   |   |   |   |"
det(12,Black,Blue
Output(1,8," A "
det(12,Black,Magenta
Output(1,12," B "
det(12,Black,Green
Output(1,16," C "
det(12,Black,Orange
Output(1,20," D "
det(12,0,0,151,151
Output(2,1,"det(12,   ,   ,   ,   )"
0->A:0->B:255->C:255->D
Output(2,8,A
Output(2,12,B
Output(2,16,C
Output(2,20,D
Output(3,1,"--------------------------"
Output(7,1,"--------------------------"
Output(8,1,"Foreground      Background"
Output(9,1,"-----  bolduparrow=+1 and bolddownarrow=-1  ----"
Output(10,1,"    |    |      |    |    "
det(12,Black,Blue
Output(10,1," +1 "
det(12,Black,Magenta
Output(10,6," +1 "
det(12,Black,Red
Output(10,11," Quit "
det(12,Black,Green
Output(10,18," +1 "
det(12,Black,Orange
Output(10,23," +1 "
det(12,300
real(7,9,0,50,160,25,255,1
real(7,9,0,50,160,25,255,1
Output(5,1,"Your text                 "
1->P
Repeat K=13
Repeat Ans
getKey
End
Ans->K
P+(Ans=25)->P
P-(K=34)->P
A+P(K=11)->A
B+P(K=12)->B
C+P(K=14)->C
D+P(K=15)->D
If A<0
A+256->A
If A>255
Then
det(12,0,0,151,151
A-256->A
Output(2,8,"   "
End
If B<0
B+256->B
If B>255
Then
det(12,0,0,151,151
B-256->B
Output(2,12,"   "
End
If C<0
C+256->C
If C>255
Then
det(12,0,0,151,151
C-256->C
Output(2,16,"   "
End
If D<0
C+256->C
If D>255
Then
det(12,0,0,151,151
D-256->D
Output(2,20,"   "
End
If P=26
25->P
If P=~26
~25->P
If abs(P)=P
Then
det(12,Black,Blue
Output(10,1,"    "
Output(10,2,"+
Output(10,3,P
det(12,Black,Magenta
Output(10,6,"    "
Output(10,7,"+
Output(10,8,P
det(12,Black,Green
Output(10,18,"    "
Output(10,19,"+
Output(10,20,P
det(12,Black,Orange
Output(10,23,"    "
Output(10,24,"+
Output(10,25,P
Else
det(12,Black,Blue
Output(10,1,"    "
Output(10,2,"-"
Output(10,3,~P
det(12,Black,Magenta
Output(10,6,"    "
Output(10,7,"-"
Output(10,8,~P
det(12,Black,Green
Output(10,18,"    "
Output(10,19,"-"
Output(10,20,~P
det(12,Black,Orange
Output(10,23,"    "
Output(10,24,"-"
Output(10,25,~P
End
det(12,0,0,151,151
Output(2,8,A
Output(2,12,B
Output(2,16,C
Output(2,20,D
det(12,A,B,C,D
Output(5,1,"Your text"
End
ClrHome
real(0,1,0,1
det(12,A,B,C,D
Output(7,1,"Your text color"
det(12,300
Disp "det(12,A,B,C,D)","","A=","B=","C=","D="
Output(3,3,A
Output(4,3,B
Output(5,3,C
Output(6,3,D
Pause
  
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 UTC - 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