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.

Newcomers DBPro Corner / What to use instead of GOTO

Author
Message
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 23rd Jan 2007 00:15 Edited at: 23rd Jan 2007 00:16
for a while i thought GOTO was awesome, i was told otherwise many times but no-one would tell me what to replace it with.

I decided I'd share with you why not to use it because i thought it was awesome untill i stopped using GOTO's and my code went from this



to this



ok that metaphor is probably lame but anyway its tidy code now


there are 2 alternatives that i know of

GOSUB - goes to a chosen label and returns to where it was called when it reads the return command



in that example it skips the end of the program and goes to the loop then returns and ends program

Functions - My personal favourite alternative instead of this



Its much tidier to put



I hope this helps understand why people tell you not to use Goto's because to me it makes coding hell, But you may think "how will i ever find the function with all those lines of code?" simple! go to the functions tab on the right hand side of the screen and click the function you want to go to because it has a list of all declared functions.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Jan 2007 02:07
I'm glad you finally saw the light.

You can learn things not from just your own treads but others as well... you just gotta keep your eyes open.

My second message in this tread talks about "goto" and the alternatives (posted 1-17-07):
http://forum.thegamecreators.com/?m=forum_view&t=97880&b=10

Login to post a reply

Server time is: 2024-09-25 17:30:13
Your offset time is: 2024-09-25 17:30:13