Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: meishe91 on April 07, 2010, 07:46:27 pm

Title: For( Loop Issues
Post by: meishe91 on April 07, 2010, 07:46:27 pm
Ok, so I'm creating a program and everything is working fine but then I get to two consecutive For( and for some reason it is either executing them incredibly fast with false information or is skipping right over them. It is something inside that code because when I isolated that code into another program to test it it does the same thing. Hopefully someone can help me here.

Here is the code in question:

Code: [Select]
For(E,-B+1,-B+D-1
For(F,A+1,A+C-1
Str1+sub("10",1+pxl-Test(E,F),1→Str1
End
End

For testing I was just using:
A=44
B=-27
C=7
D=-7
_→Str1


Also, I just ran a little test thing and it appears that it is the second For( loop that isn't going. Does the variable "F" have issues with the For( command?

Thanks, everyone.
Title: Re: For( Loop Issues
Post by: Will_W on April 07, 2010, 07:49:00 pm
For(E,-(-27)+1,-(-27)+(-7)-1
For(E,28,19
That's the problem, the start value is higher than the end.
Title: Re: For( Loop Issues
Post by: meishe91 on April 07, 2010, 08:03:18 pm
Oh, wow. I knew it'd be something dumb like that :P Thanks Will_W :)
Title: Re: For( Loop Issues
Post by: DJ Omnimaga on April 07, 2010, 08:05:42 pm
That happened to me often in the past ^^ sometimes took ages for me to figure out.

Fortunately, TI-BASIC and Axe parser are nice enough to not treat such For loops as endless loops, though, like other languages do, according to Will_W
Title: Re: For( Loop Issues
Post by: Will_W on April 07, 2010, 08:10:28 pm
in java, its for(variable;condition;what to do to make the variable approach the condition)
usually something along the lines of for(int i=0;i>5;i++)
a > condition will behave like BASIC and Axe, but if you did i=5 and started with i=6 or something, it would behave strangely, either giving a compile time error, or incrementing until i overflows and becomes 5.
Title: Re: For( Loop Issues
Post by: DJ Omnimaga on April 08, 2010, 10:00:30 pm
wow Java syntax seems weird x.x

It reminds me a bit Casio calcs, except the i++ part of your code that I don't understand.

I think it was something like For 1 to 10->X but I could be wrong. There was another argument for increment rate.

Another thing with TI-83+ for( loops is to always close the parhentesis when your For loop contains only a If:Then:code:End. If the condition is false or something, the For loop takes considerably longer to process and sometimes the rest of the program will run slower, as if a massive memory leak of OVER 9000 KB of RAM occured.

(Texas Instruments should really spend their efforts into fixing their OSes than into DMCA notices and C&D letters.)
Title: Re: For( Loop Issues
Post by: meishe91 on April 08, 2010, 10:05:11 pm
Ztrumpet told me it was just to close them if only an If statement occurs after a For( loop and that If/Then were fine without the closing ones, I believe. I would have to check my emails with him to be sure that's what he said, but ya.
Title: Re: For( Loop Issues
Post by: calc84maniac on April 08, 2010, 10:08:12 pm
in java, its for(variable;condition;what to do to make the variable approach the condition)
usually something along the lines of for(int i=0;i>5;i++)
a > condition will behave like BASIC and Axe, but if you did i=5 and started with i=6 or something, it would behave strangely, either giving a compile time error, or incrementing until i overflows and becomes 5.
I think you mean a < condition, because it acts like a "while" and not "repeat"
Title: Re: For( Loop Issues
Post by: DJ Omnimaga on April 08, 2010, 10:55:04 pm
Ztrumpet told me it was just to close them if only an If statement occurs after a For( loop and that If/Then were fine without the closing ones, I believe. I would have to check my emails with him to be sure that's what he said, but ya.
It's actually mentionned on TI-BD site:

http://tibasicdev.wikidot.com/for

In the optimizations part.
Title: Re: For( Loop Issues
Post by: meishe91 on April 08, 2010, 11:04:57 pm
Ya, TIBD says its only when an If command (when the condition is false) stands alone after a For(. Unless I'm reading it wrong.
Title: Re: For( Loop Issues
Post by: DJ Omnimaga on April 08, 2010, 11:31:40 pm
yep this is what it says, and my mistake, no Then instructions
Title: Re: For( Loop Issues
Post by: meishe91 on April 09, 2010, 12:01:55 am
Oh ok, no worries. Thanks for pointing it out though, I might not have remembered otherwise :P
Title: Re: For( Loop Issues
Post by: Deep Toaster on June 01, 2010, 08:48:46 pm
Ya, TIBD says its only when an If command (when the condition is false) stands alone after a For(. Unless I'm reading it wrong.

Strange, I just tested it out, and the time is almost equal in all four conditions: with the If statement true or false, and with or without the closing parenthesis on the For(.
Title: Re: For( Loop Issues
Post by: DJ Omnimaga on June 01, 2010, 09:25:58 pm
Try:

0->A
For(Z,0,100
If A=1:0
End

then compare with

0->A
For(Z,0,100)
If A=1:0
End