[TI BASIC] Number of IF statements allowed?

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

CDI wrote:threefingeredguy, if you are referring to Metroid 1, that was a failure at coding and I still need to update it with the Metroid Pure engine(s). Metroid Infinity is at least 3x faster in some places, and up to 4 or 5x faster so HA ;)
I wasn't referring to Metroid 1. :)
benryves wrote:
threefingeredguy wrote:Also, when there is support for Visual C++ apps (coming in the future, I hear) you should be able to run Brass.
For the record, I'm no masochist. Brass is written in C#, not C++, and so will run under MacOS via Mono.

However, automatic app signing relies on COM interop with TI's Wappsign, so won't work.
Ah, C#. My mistake. I wasn't aware support was already added since I don't follow .NET development. Though in this day and age that's one of the few things I really SHOULD learn if I want to be successful in programming.
Image
User avatar
CDI
Maxcoderz Staff
Posts: 321
Joined: Tue 24 May, 2005 7:25 pm
Location: If I find out, you'll be first to know.
Contact:

Post by CDI »

Well, Metroid II wasn't my fault, and Metroid Pure can be faster, and ontop of everything, Metroid Infinity is as fast on the normal 83+, as Metroid II was on an SE
ImageImage
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

This is a reply to the question "how many if statements can you have?":
you can have as many as the current memory allows,
to check it in absolute values use these 2 programs and compare their results (I dunno the relationship between them tough)

Code: Select all

PROGRAM:A
:Ans+1
:prgmA

Code: Select all

PROGRAM:B
:Ans+1
:If 1
:Then
:prgmB
and run it like this "0:prgmA/B", when the "ERR: Memory" occurs "Ans" the results
My results with 23630 free ram are:
prgmA: 1388
and prgmB: 472
EDIT: mixed prgmA and prgmB

Ok, this is a completely useless post but it is fun tough...
Last edited by driesguldolf on Sat 19 May, 2007 10:03 am, edited 1 time in total.
User avatar
Halifax
Sir Posts-A-Lot
Posts: 225
Joined: Mon 01 Jan, 2007 10:39 am
Location: Pennsylvania, US

Post by Halifax »

King Harold wrote:"If" does not go with "End"
"If" "Then" goes with "End"

"If" is just used on its own and it will skip the NEXT like when FALSE, "If" "Then" will skip everything until the next "End" when FALSE. If the condition is true then they do nothing except take time. (TRUE being 1 or greater)

Also, those "End"s you have will never be executed since you "Goto" before the parser gets to them. "Goto"s are relatively slow and unreachable code is not very useful.


So, to fix your code, add a "Then" after every "If" ("Then" can be found right between "If" and "Else")

Or better yet:

Code: Select all

1->A
1->B
repeat 0
repeat Ans
getKey
End
Ans->K
Output(A,B,"   %that is 1 space, and this is a comment
B+(K=26)(B<16)-(K=24)(B>1)->B
A+(K=34)(A<8)-(K=25)(A>1)->A
Output(A,B,"?
End
Untested but should work ('work' being defined as "moves a question mark around the screen using the arrow keys")

Lesson learned: conditionals build into functions are faster than If/Then statements.


PS: the number of IF statements allowed is unlimited except by the size of the RAM.
I just wanted to show that this is actually simple when you think about TI's parser. Let's examine this line:

B+(K=26)(B<16)-(K=24)(B>1)->B

Why does this work?? Well let's look at it. TI will parse this and "simplify" it to true and false(1 and 0 respectivly). So let's say K = 26 and B = 1. Well then it would turn into this.

B+(1)(1)-(0)(0)->B

which is B+(1*1)-(0*0)->B which I think you should understand. Well let's say it would be.

B+2(K=26)(B<16)-2(K=24)(B>1)->B then that turns into B+2*(1*1)-2*(0*0)->B

It is a very ingenious trick for whoever thought it up. This line could also be optimized for size though too. It will stay the same speed though. Here's the benchmarks.

B+(K=26)(B<16)-(K=24)(B>1)->B
Bytes: 37
200 repeats: 3 seconds
1000 repeats: 12 seconds

B+(K=26 and B<16)-(K=24 and B>1->B
Bytes: 34
200 repeats: 3 seconds
1000 repeats: 12 seconds
Post Reply