• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Return back in a specific line C++

Joined
Dec 2, 2009
Messages
3,353 (0.59/day)
System Name Dark Stealth
Processor Ryzen 5 5600x
Motherboard Gigabyte B450M Gaming rev 1.0
Cooling Snowman, arctic p12 x2 fans
Memory 16x2 DDR4 Corsair Dominator Pro
Video Card(s) 3080 10gb
Storage 2TB NVME PCIE 4.0 Crucial P3 Plus, 1TB Crucial MX500 SSD, 4TB WD RED HDD
Display(s) HP Omen 34c (34" monitor 3440x1440 165Hz VA panel)
Case Zalman S2
Power Supply Corsair 750TX
Mouse Logitech pro superlight, mx mouse s3, Razer Basiliskx with battery
Keyboard Custom mechanical keyboard tm680
Software Windows 11
Benchmark Scores 70-80 fps 3440x1440 on cyberpunk 2077 max settings
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! :cry:
 
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...
 
Last edited:
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.
 
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.
 
I find goto can be dead handy for debugging when you just want to skip sections of code temporarily.
 
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
 
...or pre-processors (like #ifdef).
 
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
 
xkcd-goto.png


Lol, we just got goto in PHP recently. We're as hip as Basic! ;)
 
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
 
I've only ever used goto in batches because there's really no alternative.
 
Last edited:
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? :roll:
(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.
 
Back
Top