PDA

View Full Version : Do you use goto???


MrSeanKon
05-21-2007, 10:41 AM
Vote and discuss of course.
Sometimes it is necessary IMHO.

DanTheBanjoman
05-21-2007, 10:44 AM
Hell yes, I had a teacher who went mental every time I used goto, kept telling me how bad it is and all. Quite a good motivation to use it. On the other hand, I hardly ever program anything, and when I do it's something really small and simple. I'd say goto works great in simple things.

MrSeanKon
05-21-2007, 10:55 AM
DanTheBanjoman do you program in Fortran??
If yes it is common the goto usage.

DanTheBanjoman
05-21-2007, 11:00 AM
DanTheBanjoman do you program in Fortran??
If yes it is common the goto usage.

Never touched it.

Kreij
05-24-2007, 03:30 AM
I thought that goto statements were outlawed in the Geneva Convention :twitch:
They were considered too much like torture for the code maintainers.

I have not used a goto in about 20 years.

pt
05-24-2007, 03:36 AM
missed an option for vote
- wtf is goto?

Kreij
05-24-2007, 03:43 AM
missed an option for vote
- wtf is goto?

In certain programming languages you can label a line of code by line number or a label and send the program execution to that line under specific instances.

Such as ...

1000 do something cool
1001 if results are not really cool GOTO 1000
1002 that was really cool

Bad example, but you get the drift.

PVTCaboose1337
05-24-2007, 04:02 AM
I have used it in actionscript

gotoandplay(1);

that plays frame 1 of the scene

aximbigfan
05-24-2007, 04:12 AM
sure, why not?


chris

W1zzard
05-24-2007, 09:38 AM
yes i use it i in c/c++. sometimes miss having it in php. but i use it rarely only when it makes sense

mikek75
05-24-2007, 11:27 AM
Ah, at last, a piece of this thread I understand from my ZX81 days...Who can forget the simple pleasure of typing in the local electrical shop:

10 PRINT " You are a wanker "
20 GOTO 10

Happy days...

gamer210
05-24-2007, 02:26 PM
Aside from some programming in MIPS, I don't think I've ever used goto.

DanTheBanjoman
05-24-2007, 03:21 PM
missed an option for vote
- wtf is goto?

If you used it you knew what is was. Therefor you don't use it. ie your answer is there, it's "no"



Also, goto doesn't have to apply to linenumber, and even cmd.exe understands it
batchfile:

:start
net send 192.168.0.8 Hello world
goto start


192.168.0.8 is W1zzards IP and he runs the messenger service. Just in case you wish to complain about it being disabled by default nowadays.

Zero Cool
05-24-2007, 11:46 PM
isnt that his internal IP adress? the one within the network?

zekrahminator
05-24-2007, 11:49 PM
missed an option for vote
- wtf is goto?

Option added :p.

Zero Cool
05-25-2007, 12:23 AM
oh I forgot I use it in school sometimes
eg.
goto.hell()

Grings
05-25-2007, 12:43 AM
i remember using goto programming my spectrum, but i havent used it this century

aximbigfan
05-25-2007, 02:51 AM
oh I forgot I use it in school sometimes
eg.
goto.hell()

wait, isnt that javascript? i didnt know that js had a goto function...


chris

Zeratul_uy
05-25-2007, 02:56 AM
What is it for? :D

aximbigfan
05-25-2007, 03:08 AM
What is it for? :D

goto is a fucntion thart when runs, goes to a certain area of code. for example:

MSDOS

+
@echo off
:1
echo HELLO WORLD!
goto 1
+
this would produce an infinate loop of the script printing "HELLO WORLD".

it is more often used in a situation liek this:

in this example we assume that error level 0 means that the source fiel is missing, error level 1 means that the file was sucsefully copyied.

+
@echo off
echo please wait, copying...
xcopy hello.txt /dest/
if errorlevel = 0 goto 0 (yes, i prolly got this wrong, it been a long time)
if errorlevel = 1 goto 1 (yes, i prolly got this wrong, it been a long time)
:0
echo ERROR! file not found.
goto ge
:1
echo file copy sucsesful!
goto ge
:ge
exit?
pause
+

in the above example, ifthe file is missing, then it issues an error, then jumps to a gobal exit function, if it was sucsesful, it issues a the message, and goes to the global exit fuinction.

now, i know i prolly got parts of the batch code wrong, it has been a very long time since i activly coded in batch.


chris

DanTheBanjoman
05-25-2007, 06:50 AM
isnt that his internal IP adress? the one within the network?
Doubt it. The range is reserved for LANs though yes.

MrSeanKon
05-29-2007, 04:35 PM
Go To Statement Considered Harmful (http://www.acm.org/classics/oct95/) check the link :)

Zeratul_uy
05-29-2007, 11:18 PM
goto is a fucntion thart when runs, goes to a certain area of code. for example:

MSDOS

+
@echo off
:1
echo HELLO WORLD!
goto 1
+
this would produce an infinate loop of the script printing "HELLO WORLD".

it is more often used in a situation liek this:

in this example we assume that error level 0 means that the source fiel is missing, error level 1 means that the file was sucsefully copyied.

+
@echo off
echo please wait, copying...
xcopy hello.txt /dest/
if errorlevel = 0 goto 0 (yes, i prolly got this wrong, it been a long time)
if errorlevel = 1 goto 1 (yes, i prolly got this wrong, it been a long time)
:0
echo ERROR! file not found.
goto ge
:1
echo file copy sucsesful!
goto ge
:ge
exit?
pause
+

in the above example, ifthe file is missing, then it issues an error, then jumps to a gobal exit function, if it was sucsesful, it issues a the message, and goes to the global exit fuinction.

now, i know i prolly got parts of the batch code wrong, it has been a very long time since i activly coded in batch.


chris

That's just what i thought it was... LOL xD
Kinda complicated isn't it?

Oliver_FF
05-31-2007, 11:04 AM
This really depends on how you use the goto command. If you use it to break out of a major loop or something, that's some seriously bad misuse of the programming language :p

TheMasterOfSinanju
06-18-2007, 04:54 AM
Yes, because in VB3-6, where I did most of my learning professionally @ least? It was the ONLY "structured err handling" I knew of!

E.G.-> On Error GoTo

Will I use it now? Not usually, but sometimes, if you keep it going to '1 exit' & don't 'cut back' up into your code, creating spaghetti logic situations? It CAN be useful!

Delphi & VB.NET have something that one of my Technical/Intellectual heroes in Anders Heijelsberg designed in Try-Catch (Delphi has Try Except/Finally) & I'd rather use that though for err traps/custom err-exception handlers though, @ least nowadays!

APK

MrSeanKon
06-28-2007, 10:35 AM
DelphiThis language based on Pascal which designed for students and teaches the programming style.
But Pascal and Delphi has goto. :cool:
IMHO it is a useful statement but we must be careful when use it.