0

In this simple program a point traverses an array diagonally and bounces off the walls. Every pixel it touches changes color.

On my TI 84+ CE, the infinite while loop stops prematurely at the same spot every time. Why?

enter image description here

0→X
0→Y
1→C
1→D

{11,20→dim([A]
For(E,1,20,1)
    For(F,1,11,1)
        0→[A](F,E)
    End
End

{1,2→dim([B]
21→[B](1,1
21→[B](1,2

{1,2→dim([C]
12→[C](1,1
12→[C](1,2

ClrHome
ClrDraw

While 1
    If X≠[B](1,2) and Y≠[C](1,2)
    Then
        Pxl-On(Y,X,RED
        X+C→X
        Y+D→Y
    Else
        If X≥[B](1,2)
        Then
            [B](1,1)-[B](1,2)→[B](1,2)
            C­1→C
        End
        If Y≥[C](1,2)
        Then
            [C](1,1)-[C](1,2)→[C](1,2)
            D­1→D
        End
    End
End
4444
  • 3,541
  • 10
  • 32
  • 43
  • 1
    What are the values of `X` and `Y` when the loop apparently stops? What are the expected range of values of `X` and `Y`? – alvits Sep 03 '16 at 02:00
  • 1
    Try using `Lbl` and `Goto` instead, see if that gives you different results – JFed-9 Sep 06 '16 at 16:17
  • 1
    I'll bet the loop isn't stopping, but the If statement inside stops evaluating to true. – Timtech Sep 17 '16 at 17:40

1 Answers1

1

I would guess that your loop does not stop, but nothing happens because X<B and Y<C. I am personally unfamiliar with the Ti-84+ CE version of Ti-Basic, but, as people have suggested in the comments above, look at the X and Y values when the loop appears to stop working. If they are too low, you have your answer. Good luck.

Scott Mikutsky
  • 746
  • 7
  • 21