Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started 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:
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.
-
For(E,-(-27)+1,-(-27)+(-7)-1
For(E,28,19
That's the problem, the start value is higher than the end.
-
Oh, wow. I knew it'd be something dumb like that :P Thanks Will_W :)
-
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
-
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.
-
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.)
-
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.
-
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"
-
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.
-
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.
-
yep this is what it says, and my mistake, no Then instructions
-
Oh ok, no worries. Thanks for pointing it out though, I might not have remembered otherwise :P
-
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(.
-
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