Posted: Sun Feb 01, 2009 3:28 pm Post subject: Exit statments
Background -
Hi so I'm new to the forum but I followed most of the oot tutorials on classes in the tutorial forum and now I'm making a text RPG. I have mostly based it off of the classes III tutorial but I rewrote the entire code so I could learn it well.
Question -
I want to make my program efficient in doing what it needs(don't we all). I want to have the program exit this entire procedure once it does what I need, If you can point me to a tutorial on exits or just plain out write me a small one for this case it would be helpful. I would like to know most if those exits in the if statement will make it leave the following for i loops.
code:
proc Equip (GOAL, NAME : string)
if GOAL = "equip" then
for i : 1 .. upper (INV)
if Item (INV (i)).NAME = NAME then
if Item (INV (i).TYPE = "Weapon" then
WEP := INV (i)
INV (i) := nil
elsif Item (INV (i).TYPE = "Shield" then
SHLD := INV (i)
INV (i) := nil
end if
exit % will this exit statement make that for i loop \/ exit prematurely?
end if
end for
else
end if
end Equip
I cut much of the code out that was unneeded so if you see a reason the program wont work ignore it I just need that exit statement question answered please.
Thanks to anyone who helps.
Sponsor Sponsor
andrew.
Posted: Sun Feb 01, 2009 8:13 pm Post subject: RE:Exit statments
When it does that first if statement, it will exit. Put something like exit when blah = blah to make it exit when a certain condition is met.
DanielG
Posted: Mon Feb 02, 2009 11:32 am Post subject: RE:Exit statments
since this is a proc, you can also use return, but exit when is probably better (unless you want to exit in the middle of a nested loop).