Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Anti-Anti-goto. Post Here!

Author
Message
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 5th Apr 2011 13:53
Or, how I do it:



Jeku
Moderator
20
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 6th Apr 2011 00:11
@thenerd - Why do you do it that way instead of as a function? It would save you a lot of code.


Senior Web Developer - Nokia
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 6th Apr 2011 13:32
True. I'm a big fan of select/case, but that probably isn't the best place to use it... The best way would be to have one engine loop that could handle all the levels, and like Grog has it just load the content at the end of levels. That way, you could eventually add levels without any hard coding.

I also have a horrible habit of using GOTO to exit from loops instead of exit.

Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 6th Apr 2011 14:49
The Using GOTO for EXIT thing isn't that uncommon really. It's not always convenient to exit the loop at the next instruction, so jumping out to a user defined location isn't the end of the world.

For stuff like the building levels, then it's a good idea to avoid hard coding them into the game as much as possible. See-> Separate Subroutines for Each Course

The whole GOTO thing has been done to death. Tutorial-About-GOTO

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 6th Apr 2011 15:50
I luv gotos



TheComet

Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Apr 2011 22:14
Quote: "I luv gotos"


Ooowww!... my eyes!!

TheComet, you found a new use for GOTO... code comedy!

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 6th Apr 2011 22:59
I'm sure if I ever found a valid reason to use Goto, then I probably would use it.

However, It's not happened yet.

I also grew up with Goto, I taught myself to program on a ZX Spectrum; which used line numbers as well. That was amazingly frustrating at times.

Jeku
Moderator
20
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 7th Apr 2011 09:48
Quote: "The Using GOTO for EXIT thing isn't that uncommon really. It's not always convenient to exit the loop at the next instruction, so jumping out to a user defined location isn't the end of the world. "


Hmmm, but wouldn't you just use the BREAK command to exit the loop before the next instruction? I know that's what I use in C++ or PHP.


Senior Web Developer - Nokia
PrimalBeans
13
Years of Service
User Offline
Joined: 14th Oct 2010
Location: The sewer.... hunting alligatiors.
Posted: 7th Apr 2011 10:12
Quote: "True. I'm a big fan of select/case, but that probably isn't the best place to use it... The best way would be to have one engine loop that could handle all the levels, and like Grog has it just load the content at the end of levels. That way, you could eventually add levels without any hard coding.

I also have a horrible habit of using GOTO to exit from loops instead of exit."
switch is the GOTO in sheeps clothing.... lol so really what your doing isnt much different... basically its a simplified encasulated goto... which is ok... lol. Thats when its ok to use. not when it gotos half way across you code.

crispex
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location:
Posted: 7th Apr 2011 13:49
As stated, the only ever use I've ever used GOTO for is for VB error trapping. It serves little purpose beyond that, as conditional statements in VB are by far the easiest things you will ever do.

Which reminds me, I don't know why people beat up on VB, I guess people hate things that are easy. I mostly use it for personal things like financial calculators anyway.

I just now realized I've had a typo in my signature for the past 3 years.
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 8th Apr 2011 07:37 Edited at: 8th Apr 2011 07:39
Quote: "
Hmmm, but wouldn't you just use the BREAK command to exit the loop before the next instruction? I know that's what I use in C++ or PHP.
"


In nested loops there's often more than one pathway the programmer might want.

a)




b)



TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Apr 2011 12:31 Edited at: 8th Apr 2011 21:37
The first code snippet would only exit the first loop.

[EDIT] never mind...

TheComet

Ermes
20
Years of Service
User Offline
Joined: 27th May 2003
Location: ITALIA
Posted: 8th Apr 2011 12:47
about sharing source, when i read example snippets or examples on using shaders, it is very nested and highly skilled structure just to show "hey, looks how i'm skilled on making code so unreadable!"

goto is clear. go there. stop.


Ciao facce da sedere!
Indicium
15
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 8th Apr 2011 19:40
Quote: "The first code snippet would only exit the first loop."


As the comments state.

Login to post a reply

Server time is: 2024-05-18 11:23:35
Your offset time is: 2024-05-18 11:23:35