yeah, and a little speed to (less to translate), so it is good for that stuff (/me makes note for programs).
-
Harq
- Calculator Deity (Posts: 1857)
- 12 Jul 2006 05:45:34 pm
- Last edited by Harq on 12 Jul 2006 05:46:52 pm; edited 1 time in total
CalcMan06 wrote:
Oh, so Repeat is essentially a primitive do-while loop? I'll have to remember that.
Repeat is a reverse while loop except it ALWAYS goes through atleast once. It keeps executing until the condition is false.
ex.
Code:
repeat k=1
code here
end
keeps on repeating until k /= 1.
- rivereye
- Future Admin (Posts: 5546)
- 12 Jul 2006 05:46:02 pm
- Last edited by rivereye on 12 Jul 2006 05:51:33 pm; edited 1 time in total
While is, do while the condition is true
Repeat is do while the condition is false, but now I see a real difference between the two.
Repeat is do while the condition is false, but now I see a real difference between the two.
Alright, Repeat is do-while until the condition is true.
And rivereye, did you mean, "Repeat is do while the condition is false"?
And rivereye, did you mean, "Repeat is do while the condition is false"?
Actually, I think Repeat should be phrased as "Do until condition is false." That way you get the indication that it executes and then checks.
Repeat is all I use now. Going through some of my older programs, replacing While with Repeat saved me several bytes since I didn't have to do something like number->variable to make sure the loop is executed. As for Calcman's program, there are a few optimizations:
Code:
Code:
You should also add PlotsOff at the top of the program. I don't think you will use some of the functions at the top of the program, like ClrHome and some others before setting the window variables, so check them and if you don't need it, remove it. What's in Pic0? I also noticed you don't modify W in While W=1, which should be shortened to While W. You should also add getkey->K at the beginning of the While loop, and change all occurrences of getkey=value to K=value. As someone mentioned, if you do not press a key between successive getkeys, the second getkey will equal 0.
Code:
:Input "P1?",Str1
:While length(Str1)>7
:Disp "<= 7 chars.
:Input "P1?",Str1
:End
:Input "P2?",Str2
:While length(Str2)>7
:Disp "<= 7 chars.
:Input "P2?",Str2
:End
Code:
:Repeat length(Str1) < 7
:Input "P1 <= 7 chars. ",Str1
:End
:Repeat length(Str2) < 7
:Input "P2 <= 7 chars. ",Str2
:End
You should also add PlotsOff at the top of the program. I don't think you will use some of the functions at the top of the program, like ClrHome and some others before setting the window variables, so check them and if you don't need it, remove it. What's in Pic0? I also noticed you don't modify W in While W=1, which should be shortened to While W. You should also add getkey->K at the beginning of the While loop, and change all occurrences of getkey=value to K=value. As someone mentioned, if you do not press a key between successive getkeys, the second getkey will equal 0.
One little problem with your Repeat code, Repeat always executes at least once. So it would prompt to enter the name again regardless if it were valid.
Pic0 is the 8X8 chess board with the pieces on it. It looks like this:
Highlight it, and you will see a bunch of space. That space wil be used later for the game clock and names and such.
I've also updated the program. The last stuff at the end is for debugging purposes, and will be removed.
Code:
Pic0 is the 8X8 chess board with the pieces on it. It looks like this:
Highlight it, and you will see a bunch of space. That space wil be used later for the game clock and names and such.
I've also updated the program. The last stuff at the end is for debugging purposes, and will be removed.
Code:
::"2-player chess.
:PlotsOff
:ClrHome
:ClrDraw
:CoordOff
:GridOff
:AxesOff
:LabelOff
:ExprOff
:FnOff
:0→Xmin
:94→Xmax
:0→Ymin
:62→YMax
:1→XScl
:1→YScl
:Input "P1? ",Str1
:While length(Str1)>7
:Input "P1 ≤ 7 chars. ",Str1
:End
:Input "P2? ",Str2
:While length(Str2)>7
:Input "P2 ≤ 7 chars ",Str2
:End
:RecallPic 0
:Text(7,66,Str1
:Text(55,66,Str2
:8,8→dim([A]
:4,1,0,0,0,0,1,4→∟ROOK
:3,1,0,0,0,0,1,3→∟KNIG
:2,1,0,0,0,0,1,2→∟BISH
:5,1,0,0,0,0,1,5→∟QUEE
:6,1,0,0,0,0,1,6→∟KING
:List►Matr∟ROOK,∟KNIG,∟BISH,∟QUEE,∟KING,∟BISH,∟KNIG,∟ROOK,[A]
:[A]→[B]
:1→W
:1→R
:1→C
:Pt-Change(C,R
:While W
:Repeat Ans
:getKey
:End
:Ans→K
:If K=26 and C<54
:Then
:Pt-Change(C,R
:C+8→C
:Pt-Change(C,R
:End
:If K=25 and R<49
:Then
:Pt-Change(C,R
:R+7→R
:Pt-Change(C,R
:End
:If K=24 and C>8
:Then
:Pt-Change(C,R
:C-8→C
:Pt-Change(C,R
:End
:If K=34 and R>7
:Then
:Pt-Change(C,R
:R-7→R
:Pt-Change(C,R
:End
:If K=105
:DelVar W
:End
:Pt-Change(R,C
:ClrHome
:Disp R,C
:Output(1,1,"
KermMartian wrote:
I never used to use Repeat until I discovered how useful it is for stuff.
I didn't know about it until I was looking through some code here and wondered what it did. I experimented and discovered how useful it was =D
KermMartian wrote:
I admit I still don't use IS( and DS( though. Does anyone else here use them?
no. Also, you need to redo the area of the 1337 guide that says that 'they are essentially mistakes'
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
» Go to Registration page
» Goto page Previous 1, 2, 3 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 2 of 3
» 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
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