Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-02-2008, 07:00 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
goto's are only useful ( really ) when you want to break out of two loop controls. They are quite obfuscating otherwise. Additionally, there are numerous reports telling us that the more goto's there are in a code, the higher the complexity is.

Plus... There'd be quite a bit of problems with the environment change ( change in function / object / scope ). It's best not to use it at all... In ANY language -- Even ones that support it. The MAJORITY of the cases, they can be completely avoided. In cases that aren't... You could just make a function-call... using return foo();

If you really want to understand... Just imagine Zodiac if goto's existed.
Reply With Quote
  #2  
Old 02-02-2008, 08:08 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
Quote:
Originally Posted by Novo View Post
goto's are only useful ( really ) when you want to break out of two loop controls.
right, its quite annoying to check for a flag each time you have 2+ loops :P
or something like a breakall; that would just kill all the loops instead of the one you are in

basically what you're saying is kinda weird, that sounds like just because c++ has goto's every game only uses them instead of loops
__________________
Reply With Quote
  #3  
Old 02-02-2008, 08:42 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by projectigi View Post
right, its quite annoying to check for a flag each time you have 2+ loops :P
How does that have anything to do with wanting "goto"?
Quote:
Originally Posted by projectigi
or something like a breakall; that would just kill all the loops instead of the one you are in
It's called "return", and will end function execution there and then, regardless of how many loops you have.
Reply With Quote
  #4  
Old 02-02-2008, 08:46 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
Quote:
Originally Posted by Skyld View Post
How does that have anything to do with wanting "goto"?
PHP Code:
for( foo 0foo 100foo++ )
  {
  for( 
bar  0bar 100bar++ )
    {
    
mehfoo ][ bar ] = blub;
    if( 
/* do something that would exit the loop */ )
      goto( 
lEndL01 );
    }
  }
Label lEndL01:
//after loop 
Quote:
Originally Posted by Skyld View Post
It's called "return", and will end function execution there and then, regardless of how many loops you have.
you don't always want to end the whole function :P
__________________
Reply With Quote
  #5  
Old 02-02-2008, 08:48 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by projectigi View Post
PHP Code:
for( foo 0foo 100foo++ )
  {
  for( 
bar  0bar 100bar++ )
    {
    
mehfoo ][ bar ] = blub;
    if( 
/* do something that would exit the loop */ )
      goto( 
lEndL01 );
    }
  }
Label lEndL01:
//after loop 
you don't always want to end the whole function :P
Then structure your code better.

You could easily have those two loops in a function by themselves, and use "return" to end there, and send back the result of your function execution to the calling function.
Reply With Quote
  #6  
Old 02-02-2008, 09:24 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
Quote:
Originally Posted by Skyld View Post
Then structure your code better.

You could easily have those two loops in a function by themselves, and use "return" to end there, and send back the result of your function execution to the calling function.
if i put every loop into a own function, reading a code with 1000+ lines will kinda be annoying lol
__________________
Reply With Quote
  #7  
Old 02-02-2008, 09:36 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by projectigi View Post
if i put every loop into a own function, reading a code with 1000+ lines will kinda be annoying lol
Usually you can find a way to actually make it look better.
__________________
Do it with a DON!
Reply With Quote
  #8  
Old 02-02-2008, 08:49 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Skyld View Post
It's called "return", and will end function execution there and then, regardless of how many loops you have.
Example:

PHP Code:
function onCreated() {
  
foo bar;
  var = 
2;
  
doLoop();
  
doOtherThings();
}

function 
doLoop() {
  for (
010i++) {
    for (
010j++) {
      if (
this.stuff[i][j])
        
doLoopThings();
        return;
      }
    }
  }

__________________
Do it with a DON!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:54 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.