forums

TNT Basic Forums > Programming Q&A
If statement speed
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-15-2003 14:47

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Do if statements cause any noticable slowdowns? For example, if I have 100 if statements?

06-15-2003 17:56

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

The more important question is: Will your program work without them?

I don't know if select case is faster than if-then in TNT. Why not try both and time them?

06-16-2003 00:35

Posted by:
anoved

Location:
Upstate NY

Find more posts by anoved

select case

I didn't know TNT had a select-case command. What is its syntax?

06-16-2003 20:07

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

I don't think it has select case.

And I'll just try to figure it out I guess. It's not too much work, but I was just wondering if anyone already had an accurate measurement.

06-16-2003 22:06

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

There is no SELECT statement ( or if there is it's not mentionned in the help ).

If-end if of course slows down the program, but not very. Maybe a few milliseconds or less. It is sure that the more you have if-end if statements, the slowest it'll be. But there are many speed factors that are more important: sprites, graphics mode or hardware mode, transparency, music, etc.

Anyway, I think there is a way to speed up ( a little ) if-end if statements. ( In other software it works but I don't know about TNT because I don't know how its core is )

instead of writing:

if x>5
print "a"
end if

if x<5
print "b"
end if

if y>5
print "c"
end if

if y<5
print "d"
end if

you can write:

if x>5
print "a"
break
else if x<5
print "b"
break
else if y>5
print "c"
break
else if y<5
print "d"
break
end if

it may be a little faster because basically the computer should stop checking the block once it has found the correct one. This is mainly useful with map objects. ( if objectid=1,2,3,4... the action will be different )

06-16-2003 23:37

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

No Select Case? Jeez, I own too many versions of basic. C'est Lavie.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.