Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
About
Team
Rules
Stats
Status
Sitemap
Chat
Downloads
Forum
News
Our Projects
Major Community Projects
Recent Posts
Unread Posts
Replies
Tools
SourceCoder3
Other Things...
Omnimaga Radio
TI-83 Plus ASM File Unsquisher
Z80 Conversion Tools
IES TI File Editor
Free RAM areas
Comprehensive Getkeyr table
URL Shortener
Online Axe Tilemap Editor
Help
Contact Us
Change Request
Report Issue/Bug
Team
Articles
Members
View the memberlist
Search For Members
Buddies
Login
Register
Omnimaga
»
Forum
»
Calculator Community
»
TI Calculators
»
TI-BASIC
»
Is it possible to Goto a label in a loop?
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: Is it possible to Goto a label in a loop? (Read 3830 times)
0 Members and 1 Guest are viewing this topic.
Delnar_Ersike
Guest
Is it possible to Goto a label in a loop?
«
on:
February 22, 2007, 08:20:00 am »
This is probably a question you can all answer: Is it possible to goto a lbl in the middle of a loop and still have the loop run without any RAM leaks?
Logged
rivereye
LV8
Addict (Next: 1000)
Posts: 996
Rating: +0/-0
Is it possible to Goto a label in a loop?
«
Reply #1 on:
February 22, 2007, 08:57:00 am »
doubt it, but haven't tired it either.
Logged
>(<')
tifreak
LV11
Super Veteran (Next: 3000)
Posts: 2708
Rating: +82/-3
My Kung Fu IS strong...
Is it possible to Goto a label in a loop?
«
Reply #2 on:
February 22, 2007, 09:46:00 am »
I am not sure, nor would I want to take the time to find out, because I try to not use Lbl and Goto. It would slow down the loop considerably everytime it ran across that Goto...
Logged
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%
dinhotheone
LV6
Super Member (Next: 500)
Posts: 410
Rating: +2/-1
Is it possible to Goto a label in a loop?
«
Reply #3 on:
February 22, 2007, 10:30:00 am »
yes, it is. it was discussed in some subroutine question.
what you have to do though is return to the loop everytime. so as not to create a memory leak
ill give you a concept example and a use example
goto 1
label 0
end
label 1
while1
disp "hi"
goto 0
end
this displays hi forever. The reason being the same behind a memory leak. everytime the calc hits a while,repeat,for,if-then (i think thats al of em) the calc keeps track of it in the memory. so when you hit the end, no matter if its before of after the loop, it transports you back to the start of the loop (obviously not for if-then's of if the condition is met...) the way that it is used is in subroutines: the fastest way to find which subroutine you want is using a goto to a label at the top of the program since the compiler starts searching for the label at the top. then for each label, you have an end to transport you back to the start of the main game loop.
ie:
goto 1 "jumps over the subroutines"
label A
do the things that you gota do
end "another end if you used an if-then instead of plain if"
label1
while 1 "main game loop"
if (condition) "if you use if-then for speed then you have to have 2"
goto A --------- -------------- "end's at the end of the subroutine"
end
this is the best way to do subroutines and does not create a memory leak as long as you are absolutely sure you hit an end for everything.
Logged
trevmeister66
LV9
Veteran (Next: 1337)
Posts: 1009
Rating: +14/-5
Is it possible to Goto a label in a loop?
«
Reply #4 on:
February 22, 2007, 10:52:00 am »
or you could just not use goto's in a loop and not have to worry about it
Logged
Projects: nameless RPG: 1.0% |
Reverse Snake v1.5:
100% | Secret Project: 5% | DUNGEON: 70%
My
MW2 Blog
<-- Please visit
dinhotheone
LV6
Super Member (Next: 500)
Posts: 410
Rating: +2/-1
Is it possible to Goto a label in a loop?
«
Reply #5 on:
February 22, 2007, 11:58:00 am »
its not really that bad and its the most efficient subroutine method, i just wrote alot because i like to feel smart.
perhaps if you explained why you needed to do this then i could be of more help.
Logged
Demon
Guest
Is it possible to Goto a label in a loop?
«
Reply #6 on:
February 22, 2007, 12:24:00 pm »
You can also use a Lbl-Goto loop (like I do in the PyroEdit and PyroMap Bases)
PROGRAM:LOOP
:Lbl 0
: Goto This
: Goto That
:Goto 0
:Lbl This
:
:Goto 0
:Lbl That
:
:Goto 0
Logged
trevmeister66
LV9
Veteran (Next: 1337)
Posts: 1009
Rating: +14/-5
Is it possible to Goto a label in a loop?
«
Reply #7 on:
February 22, 2007, 12:53:00 pm »
wouldn't that actually never get to "goto that"?
Logged
Projects: nameless RPG: 1.0% |
Reverse Snake v1.5:
100% | Secret Project: 5% | DUNGEON: 70%
My
MW2 Blog
<-- Please visit
Demon
Guest
Is it possible to Goto a label in a loop?
«
Reply #8 on:
February 22, 2007, 01:16:00 pm »
If Ans=Something
Goto This
Ia Ans=Something Else
Goto That
Logged
dinhotheone
LV6
Super Member (Next: 500)
Posts: 410
Rating: +2/-1
Is it possible to Goto a label in a loop?
«
Reply #9 on:
February 22, 2007, 01:30:00 pm »
the only problem there is that if you have alot of subroutines, then your goto-label loops have to repeatedly search through the program passing over the subroutines everytime, in this case a looping structure is far more efficient because it does not have to reread over all the useless code (useless to the os at that time) to get to the label because the start of the looping structure is temporarily stored in the calcs ram. looping structures will pretty much always be faster than label-goto loops but label-goto's are easier to program.
Logged
Delnar_Ersike
Guest
Is it possible to Goto a label in a loop?
«
Reply #10 on:
February 22, 2007, 01:44:00 pm »
Thanks everyone! I think I have the answer to my question.
BTW, I was thinking of it the other way around:
:Repeat Ans>something
:(code)
:Lbl 1
:(code)
:End
:If Ans
:Then
:Goto 1
:End
Logged
Radical Pi
LV9
Veteran (Next: 1337)
Posts: 1143
Rating: +5/-2
Is it possible to Goto a label in a loop?
«
Reply #11 on:
February 22, 2007, 02:06:00 pm »
As long as you make sure you have enough End's reached, you can do it with no side effects other than speed.
Logged
One of these days I'll get a sig I'm really proud of.
dinhotheone
LV6
Super Member (Next: 500)
Posts: 410
Rating: +2/-1
Is it possible to Goto a label in a loop?
«
Reply #12 on:
February 22, 2007, 02:24:00 pm »
the problem with the code you supplied is that when you jump into the loop, the calculator doesn't know it just jumped into the loop. it will continue execution as though it were not in a loop, up untill hte point where it hits the end where it will either error due an end with no structure (if you used a plain if) or (if you used an if-then) it will see the end as the end to the if-then and continue as though nothing happened. too jump into a loop you have to be already in the loop
ie
while condition "again, main game loop"
goto 0
label 1
end
label 0
goto 1
you can only have a plain if for the jump out/in otherwise it will mem leak.
and you must always jump back in.
the only otherway to jump 'into' a loop is to jump to the top of it
ie
label1
while condition
end
goto 1
you can't really tell the complier to remember that there is a start of the loop up above. at least not with basic, you may in asm.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
Omnimaga
»
Forum
»
Calculator Community
»
TI Calculators
»
TI-BASIC
»
Is it possible to Goto a label in a loop?