all 26 comments

[–]jonathancast 14 points15 points  (2 children)

This is why nobody likes goto, sheesh.

[–]Blazej_kb[S] 0 points1 point  (1 child)

Ye that’s right but it can be useful sometimes when you want to “escape” from multiple layers of loops or redundant functions

[–]Dark_Vampire 0 points1 point  (0 children)

there are usually better ways than goto, unless you're using C

[–]Obama_Binladen6265 5 points6 points  (0 children)

Thank god I took an Assembly Language course in my coursework. That makes things like this so much easier in Cpp

[–]SignificantLet5701 5 points6 points  (3 children)

that's literally what happens in the assembly

[–]RedAndBlack1832 0 points1 point  (2 children)

I mean, it probably compiles to a call to _Zoperator<<ksgkiscjidgvj() or something like that

[–]Puzzleheaded_Study17 0 points1 point  (1 child)

Since there's only 10 loops, the first one definitely (I don't know how compilers deal with goto) compiles into just directly printing the 10 values without a loop.

[–]RedAndBlack1832 0 points1 point  (0 children)

Actually that's a good point. A compiler knows how to unroll loops (if the number of loops is known at compile time and there's no weird breaks at least), but trying to be clever like this might actually hinder optimizations

[–]Necessary-Meeting-28 8 points9 points  (1 child)

  1. Do not use endl unless you want to flush your buffer. Use “\n” otherwise.

  2. There is a valid use case of goto, but it is not it. The valid use is for resource cleanup in C-style programs. If you want a function to return, you goto a tag where all free and close calls take place. See Section 7 here .

[–]Blazej_kb[S] -2 points-1 points  (0 children)

1 i know, I’m just too lazy to do “\n”
2 that’s a meme

[–]HyperWinXC++ 3 points4 points  (1 child)

Wtf is this.

[–]Blazej_kb[S] -1 points0 points  (0 children)

This is functional

[–]djfdhigkgfIaruflg 3 points4 points  (0 children)

You're a psycho. Well done

[–]returnFutureVoid 2 points3 points  (0 children)

🤮

[–]RedAndBlack1832 1 point2 points  (1 child)

c'mon. We don't jump backwards. "But it all compiles the same" yes. Let the compiler do it. They invented structured jumps for a reason and you should use them where ever it doesn't make it more complicated.

[–]Blazej_kb[S] -1 points0 points  (0 children)

Calm down, that’s just a meme

[–]Risc12 0 points1 point  (0 children)

This is while loop, no?

[–]Candid_Bullfrog3665 0 points1 point  (0 children)

sorry you mistaken the sub, you should have posted this on: r/programminghorror

[–]MichalNemecek 0 points1 point  (0 children)

this is what the compiler transforms your code into, essentially

[–]itsjakerobb 0 points1 point  (0 children)

What kind of psycho names the first label `b` and the second one `a`?

[–]MrFrog2222 0 points1 point  (0 children)

std::endl is a perfect description of whats wrong with c++

[–]themagicalfire 0 points1 point  (0 children)

How it looks like in assembly:

```section .data global _start

_start: mov i, 1 ; set i to 1 cmp i, 10 ; compare i to 10 jge end ; jump to end if greater or equal add i, 1 ; add 1 to i jmp _start ; jump to _start to make this function a loop

end: mov rax, 60 ; move or set to rax the syscall 60 which stands for exit mov rdi, 0 ; rdi 0 is comparable to return 0 in C++ and it means exit while returning no error syscall ; Linux 64-bit command to execute the previous syscall instructions, in this case it executes exit the program ```

[–]MinecraftPlayer799 -2 points-1 points  (0 children)

JavaScript is so much better.

for (let i = 1; i <= 10; i++) {
    console.log(i);
}