Author Topic: Looping without GoTo  (Read 9286 times)

0 Members and 1 Guest are viewing this topic.

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Looping without GoTo
« Reply #15 on: December 11, 2008, 08:23:22 AM »
0
ok you guys have totaly confused me now. for some one who is just starting on his path to scripting is it easyer to learn with or with out goto's ?

You know, whatever works for you.  There are a few people here who are militantly against using gotos because some strange GOTO monster scared them when they were young.  If you find them useful, then by all means.  They are just another tool in the toolbox.  The problem with most people is they OVERUSE them. 

For you as you are just starting out, try to understand how the WHILE, REPEAT/UNTIL looping structures work also.  Then you can determine for yourself how you might want your code to loop.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline 12TimesOverTopic starter

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Looping without GoTo
« Reply #16 on: December 11, 2008, 08:27:21 AM »
0
Use whatever method suits the purpose.

If you do use goto's remember that they aren't the only way to setup a loop and that it's bad, bad, bad to jump between subs with goto's.

I've taken a liking to repeat...until statements myself but I still see the value of an appropriately placed goto now and again.

XII
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Looping without GoTo
« Reply #17 on: December 11, 2008, 08:29:49 AM »
0
If you do use goto's remember that they aren't the only way to setup a loop and that it's bad, bad, bad to jump between subs with goto's.

Amen, brotha!
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Looping without GoTo
« Reply #18 on: December 11, 2008, 08:53:08 AM »
0
Don't listen to them.... FEAR THE GOTO for they are evil  :-\

GOTO's prance around scripts like they are Gods. No matter what is going on, they have absolute control over where the code flows. And you know what they say about absolute power... yep, it Corrupts Absolutely.

Lets have a look at this little gosub. He's just enjoying his part in the script waiting patiently until he's needed, then he'll perform his function as programmed, then graciously return to the main script. He's a team player.

Code: [Select]
gosub Our_Friend
the rest of the script

sub Our_Friend
waits patiently until called
finally the moment comes
performs his part
knows he's a small part of the bigger picture
finishes up his role
happily returns control back to the script

Now lets see what GOTO does to him....

Code: [Select]
gosub Our_Friend
the rest of the script

sub Our_Friend
waits patiently until called
finally the moment comes

GOTO SOMEWHERE_ELSE

looks around confused
wonders where the script went
wonders why the script doesn't need him any more
worries it might have been something he said, or did
wonders if he should return, or not....
feels that if he did return it might be awkward for the mainscript
confusion sets in
sits idly by, crying quietly to himself, wondering why the script turned it's back on him

...... sorry..... something in my eye...... sec.......

XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Looping without GoTo
« Reply #19 on: December 11, 2008, 08:58:10 AM »
0
It's frightening what goes on in Cervezas mind!!!  ;D
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline OMGBurgers

  • Hero Member
  • *
  • Posts: 800
  • Activity:
    0%
  • Reputation Power: 7
  • OMGBurgers has no influence.
  • Respect: +44
  • Referrals: 0
    • View Profile
Re: Looping without GoTo
« Reply #20 on: December 11, 2008, 09:23:53 AM »
0
I used to use goto's a LOT but I've been really trying to cut down on them.  The main thing that is making me cut down on them is because of ScriptUO.  I hate to clutter that nifty right panel that shows all my tags/gotos with a buncha stupid goto's because I just never used whiles/repeatuntil etc.

Can't say it made the code more stable, because if you do it right it's all the same.  But I can say wow, it's really made debugging and reading it a LOT easier because you don't have to jump aroudn the tags with your eyes you just see the brackets and indents and know where your loops and all are.

I would personally use whiles/repeatuntils as much as possible, but don't be afraid of using gotos for your "main loops".  I still have a LOT to learn.  I'm sure people who read my code know that.  But hey, it works! :D

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Looping without GoTo
« Reply #21 on: December 13, 2008, 09:08:24 AM »
0
Wow this thread has not imploded yet...

Gotos = Evil

Repeat..until / While  = ! Evil.

LOL

Gotos should be used like crack .. sparingly and precautions taken.. otherwise you will soon be headed down the ugly road of addiction....
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Tags: