yeah, and a little speed to (less to translate), so it is good for that stuff (/me makes note for programs).
Oh, so Repeat is essentially a primitive do-while loop? I'll have to remember that.
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.
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.
Alright, Repeat is do-while until the condition is true.

And rivereye, did you mean, "Repeat is do while the condition is false"? Laughing
I do, what was I think, will edit.
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.
That is pretty much the simplest/easiest way to understand it.
until it is true though.
good point, 0x5.
Oh crap. Why is it so hard to write down what these two do. I had them straight in my head. Laughing
Laughing I never used to use Repeat until I discovered how useful it is for stuff. Very Happy
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:
: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:
::"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:
0x5 I never used to use Repeat until I discovered how useful it is for stuff. Very Happy


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
I admit I still don't use IS( and DS( though. Does anyone else here use them?
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'
We'll have to update that with the handy descriptions TiFreak8x came up with.
who decided that they were mistakes anyways?
CalcMan06 wrote:
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.

See that's why in my code, I don't have an Input outside of the loop.
  
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 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

 

Advertisement