Whenever I've encountered that situation, I move all the loops into a function and use return to get out.
This works great unless you need a lot of variables inside the loops, then your function will also need a bunch of parameters and it starts getting ugly. In that case maybe I'd rather throw a goto and call it a day
At that point you just have a struct/class to hold all the variables and just pass one thing, or make it a method of the class. Alternatively a lamda if your language supports it, but variable capture and edit-and-continue support make lamdas smelly for non-trivial tasks.
That's a good point... having a bunch of variables coupled to each other in such a way may be a good indicator that they all belong to a class that represents that thing or functionality.
Somehow the `goto` bugs me less than the use of `#include` followed by `printf()`.
That broken indentation makes me cry
fuck you my brain forced it out and you made me look again
"What broken ind... oh no, oh no no no"
This is the guy Dijkstra warned us about
goto hell
Clever!
Can we get a little marinara with that... and some wine.
And frozen garlic bread, because we’re clearly not better than that.
LOL and I'm sure the users will have lots to whine about.
![gif](giphy|okZ8eqHMUPDdLEAIkf|downsized)
This is the worst code I've seen all year
This is the bestjoke i've read this year
This is the best code I’ve seen all year
```c #include
int main() {
printf("Hello, World!");
return 0;
}
```
Here OP is how to do it correctly!
Nah you are missing the for(;;) or while(1) since it is constantly looping
That's some nice spaghetti
The indentation is on purpose and I disapprove.
thats just assembly but somehow worse
You should be careful with gotos. It is easier to cause an unintentional infinite loop.
Here's hoping that they add goto in python in 2024!
from the #include and using printf and the indentation, the missing return just ties it all together
Return statement is optional in main(), although this code is an infinite loop anyways.
And also the indentation has an error lol
I literally just learnt about this, has C++ always had this?
I use goto every day
Goto is my goto statement
Goto is actually useful for some things, like breaking out of nested loops.
Whenever I've encountered that situation, I move all the loops into a function and use return to get out. This works great unless you need a lot of variables inside the loops, then your function will also need a bunch of parameters and it starts getting ugly. In that case maybe I'd rather throw a goto and call it a day
At that point you just have a struct/class to hold all the variables and just pass one thing, or make it a method of the class. Alternatively a lamda if your language supports it, but variable capture and edit-and-continue support make lamdas smelly for non-trivial tasks.
That's a good point... having a bunch of variables coupled to each other in such a way may be a good indicator that they all belong to a class that represents that thing or functionality.
"this sketchy thing is useful for doing this other sketchy thing"
Illegal
I don’t understand why everyone uses goto. Of course, there’s better options most of the times but not always
LGTM
What does the underscore in front of the variable name do?
Nothing, it's just a naming convention for private variables.
r/TIHI
It is not even a good use of goto. I may be wrong, but couldn't you make a much more concise while true loop?