|  | |
11-29-2005, 08:59 PM
|
#11 (permalink)
|
Ultra Techie Join Date: Jul 2005 Posts: 530
| That would be much better suited to a do/while loop.
Do NOT use gotos for that kind of work.
__________________ Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache) |
| |
11-29-2005, 09:02 PM
|
#12 (permalink)
|
Master Techie Join Date: May 2005 Location: UK Posts: 2,749
| Ok i`ll see if i can change it, I still like goto's though in small applications that dont require 1000's of lines of code.
__________________ |
| |
11-29-2005, 10:54 PM
|
#13 (permalink)
|
Super Techie Join Date: Jun 2005 Posts: 274
| Quote: Originally posted by baronvongogo
[B]well, say I activate a lot of things such as:
void something(){
workstart:
work1
work2
work3
work4
if (work1 <=0)
goto workstart;
} | do
{
work1
work2
work3
work4
}
while(work1<=0)
that would be a much better way to do the exact same thing without using a go to statement. |
| |
11-29-2005, 10:56 PM
|
#14 (permalink)
|
Master Techie Join Date: May 2005 Location: UK Posts: 2,749
| Yes I know that now  , I still think goto's have a place somewere its a nice feature to have if you dont overuse them all over the place. I love you goto`s even if know one else does!
__________________ |
| |
12-01-2005, 08:49 AM
|
#15 (permalink)
|
Newb Techie Join Date: Oct 2005 Posts: 8
| Never Never use goto
U can efficiently program without tat |
| |
12-01-2005, 11:07 AM
|
#16 (permalink)
|
True Techie Join Date: Mar 2005 Posts: 184
| I agree that in small programs it can be useful but if you get used to using them and don't learn how to do things the proper way your code will be impossible to debug. Seriously, I have been sitting in front of the computer looking at my own code from when I first started programming and thinking "What was this idiot trying to do." then I realize "Hey that idiot was me".
__________________
Aim:Gibsonrocker03 |
| |
12-01-2005, 12:19 PM
|
#17 (permalink)
|
Ultra Techie Join Date: Jul 2005 Posts: 530
| The example I posted is, in my opinion, the only acceptable usage of goto.
__________________ Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache) |
| |
12-01-2005, 12:52 PM
|
#18 (permalink)
|
Monster Techie Join Date: Jan 2005 Location: Canada Posts: 1,522
| TheHeadFL pretty much said everything I was going to say when I read the question - down to the example he posted about breaking out of multiple loops  .. Perhaps, both of us have read the same books. lol
Traditionally, don't do it. It makes for poorly organized code which is difficult to read. There are always alternatives to using the "goto". The example mentioned, is one exception to the rule - where it is actually more "clearer" to use goto. But, keep in mind that "most of the time", the situation will not call for a goto statement and will be considered to be poor style. |
| |
12-01-2005, 06:54 PM
|
#19 (permalink)
|
Super Techie Join Date: Jun 2005 Posts: 274
| Quote: Originally posted by TheHeadFL
[B]I feel I need to clarify my statement.
For example... Code: for (something)
{
for (something)
{
for (even something else yet)
{
if (condition) {
// Get out of all the loops
}
}
}
}
| there a couple easy ways to do this without goto. 1. make all for statment exit by setting conditions in the if for example. Code: int main ()
{
for(int i=0;i<10;i++)
{
cout<<i<<" "<<endl;
for(int j=0;j<10;j++)
{ cout<<j<<" "<<endl;
for(int k=0;k<10;k++)
{
cout<<k<<" "<<endl;
if(k==2)
{
i=20;
j=20;
k=20;
}
}
}
}
return 0;
}
I admit that could become a long if statement if you had 50 or 60 for statements which brings me two the secound way I would do it. I would just make the whole nested for a int function and in the if statment have it return 0 which would exit the function and the loop.
The goto I guess would work too but if any of my teachers ever saw a goto statment in one of my program that would be a automatic many point off. |
| |
12-01-2005, 07:23 PM
|
#20 (permalink)
|
Master Techie Join Date: May 2005 Location: UK Posts: 2,749
| oops lol bit late now! oh well Its a lesson learnt and I will use other methods from now on.
__________________ |
| |  | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | |