I used this little test to understand.

For(I,1,100
Text(1,1," this is way we wash out clothes wash our clothes
End

When I checked "I" on the home screen it was 101. For me that is not a good thing because the program wants to keep running and I want it to stop. How do I fix that?

Why does it want to keep running you ask.
I have a list that is used to run my program with For(I,1, Dim(OVER1

OVER1 may look like this {1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0} for example. It will always have 16 values.

When I reach the number "7" in the list there is no more work to be done and I want the program to stop but it keeps indexing through all the "0s" and tries to use a value of "I" of 17 and my program throws an invalid dim error.
It won't try and access the 17th element. It will stop when it equals 17, because 17 is greater than 16. It won't run the loop a 17th time, but the number will be 17 afterwards.
Your test only looped 100 times
try this:

Code:
```:For(I,1,100) :Output(1,1,I :End```
Please read my post very carefully. I just want my program to do its work for 7 instances and exit. quit whatever you want to say. The program can do no useful work but my program has not been educated by some smart programmer (not me) to know how to stop the program, so on the next loop of the program it tries to put 17 into my program and it just throws an error.

Are you that smart programmer?

Not to belabor the subject. OVER1 can have a number of configurations. The issue is when we look at the last number in that list that is>0 we want to exit the program.

Code:
```For(I,1,dim(OVER1 Output(1,1,I cumsum(OVER1 -> LA //That's the cumulative sum of OVER1 store into list A - I forgot how to make the list and store characters If LA(I)=LA(dim(LA //If everything in OVER1 past the I-th term is a zero dim(LA -> I End```

I think the select or seq commands might serve you better, but frankly I don't know what they do.

EDIT: Never mind, read post on United-TI forum. Looks like I'm a little late, but I hope this still helps some.
OK, my understanding is that you want the loop to make 16 passes then have the final number be 16. If that is the case there are a couple of things I would do: you could say

Code:
```For(A,1,15) *do whatever here End *again do whatever once more ```

or you could also do

Code:
```For(A,1,16) *do whatever End A-1->A *do rest of code ```

One more thing, this may not help you much if it is a HUGE program, but what I do is I completely rewrite the code, from start to finish. This ensures that I did not mess up writing a specific portion, instead of thinking there is an error with the commands used. Did that help, sometimes I am bad at giving help

Quote:
When I reach the number "7" in the list there is no more work to be done and I want the program to stop but it keeps indexing through all the "0s" and tries to use a value of "I" of 17 and my program throws an invalid dim error.

Are you saying that somewhere in the code you have this:

Code:
`17->I`

If so then what you could do is add an “If” statement infront of the part where it says something like “L1(I)” and change it to

Code:
```If I=17:Then *all of the list stuff here End ```
john massey wrote:
When I reach the number "7" in the list there is no more work to be done and I want the program to stop but it keeps indexing through all the "0s"

I thought that the main problem is that at the end of the for loop, it needs to scan through the rest of the list to check if there are no more non-zero numbers, and exit the for loop if there are no more non-zero numbers.
Here is what I am trying as we speak. I know when ever a program exits the value of "I" is more than than the limit. In my case with a loop of 16 the number would be 17. At the top of the loop where, I believe Believe "I" will be 17. I put

If J=17: prgmWHATEVER

Because of other complications I have not been able to fully test this. I certainly believe that this is the answer. When the complications are removed I will advise.
john massey wrote:
At the top of the loop where, I believe Believe "I" will be 17. I put

If J=17: prgmWHATEVER

Wait, do you mean it's inside the for loop? If it's inside the for loop, it's not going to run, because when J is equal to 16 and it reaches the end of the loop, it gets incremented to 17 and leaves the loop because it's reached the end of the for loop.

If it's outside the loop, J is going to be 17 pretty much every time it exits the loop normally. You could use a GoTo command to call it out of the loop but that would leave a memory leak.
How are things today Emperor Wiggy, Well first I tried to use the statement referred to, inside the loop at the end of the loop. The program started running again. So I moved the statement just inside the loop at the top. I know it works because, the program exited and went to the next program.

I will keep testing. If for some reason I find this is not true, I will get in my Lear Jet and make at trip to Wiggyville for a visit.
john massey wrote:
I will get in my Lear Jet and make at trip to Wiggyville for a visit.

For a second there I swear I read "Wiggin", referring to a certain OSC series

You could also always cap the numbers the loop will reach.

Code:
```:SomeNumber (such as 16) :Ans - (Ans-dim(listname))(dim(listname)<Ans)--> SomeVariable :For(A,1, SomeVariable :*do whatever here :End ```
I just like

If J=17:prgmANY

It seems to work.
Well instead of using Goto, when your running the for loop, when the number reaches the desired limit, you can do some thing like

For(J,1,16
If J=7
16->J
End

That causes the for to stop because J has reached the limit.

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.

»
» 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