# Return back in a specific line C++



## GSquadron (Aug 26, 2011)

Hi guys!
I was programming a new game (text rpg  )
I need to go back in a line. I know the command goto,
but from what i hear it is not practical (slow)
and most important of all it always shows me this problem:

expected identifier before '(' token|

Pls help me!


----------



## ctrain (Aug 26, 2011)

goto isn't slow, the problem is you can potentially end up with a nasty code flow.

goto literally just maps to the 'jmp' instruction.


also i'm not sure if you expect people to be psychic or what...


----------



## FordGT90Concept (Aug 26, 2011)

Yeah...

Instead of goto, we usually make a separate function which accepts a reference (or value) so it can do what needs to be done without breaking the procedural order of things.  Goto hasn't really been used since BASIC.


----------



## xbonez (Aug 26, 2011)

Reiterating what others said, Goto is bad programming as it encourages spaghetti code. 

If your code absolutely needs a goto statement, that's generally a good indicator that it is time for some refactoring.


----------



## qubit (Aug 26, 2011)

I find goto can be dead handy for debugging when you just want to skip sections of code temporarily.


----------



## xbonez (Aug 26, 2011)

qubit said:


> I find goto can be dead handy for debugging when you just want to skip sections of code temporarily.



I prefer just multi-line commenting


----------



## FordGT90Concept (Aug 26, 2011)

...or pre-processors (like #ifdef).


----------



## W1zzard (Aug 26, 2011)

qubit said:


> I find goto can be dead handy for debugging when you just want to skip sections of code temporarily.



your debugger has a function to set the instruction pointer to any line in the current function.

use comments or ifdefs to disable sections of code .. missing a goto is very easy


----------



## Disparia (Aug 26, 2011)

Lol, we just got _goto_ in PHP recently. We're as hip as Basic!


----------



## W1zzard (Aug 26, 2011)

i think i maybe used goto five or six times in all the hundreds of thousands lines of code i've written. it makes sense in some very specific scenarios, otherwise use better language constructs


----------



## FordGT90Concept (Aug 27, 2011)

I've only ever used goto in batches because there's really no alternative.


----------



## Kreij (Aug 27, 2011)

W1zzard said:


> i think i maybe used goto five or six times in all the hundreds of thousands lines of code i've written. it makes sense in some very specific scenarios, otherwise use better language constructs



So ... you're admitting to 5 or 6 bad programming judgement calls? 
(Just kidding, don't kill me W1zz)

#THOUGHT : With modern progamming languages there is no real reason to use GOTOs.
The GOTO debate, however, will always continue as it transcends time and space.
If you disagree, GOTO #THOUGHT.


----------

