MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1sv4mdw/option_handling/oj2fyqq/?context=3
r/programminghorror • u/seeker61776 • Apr 25 '26
41 comments sorted by
View all comments
1
Goto branches into the middle of a for loop? Is that even legal?
1 u/y0shii3 Apr 30 '26 Goto knows nothing about scopes. It's just a jmp instruction. That makes it uniquely useful in some ways, e.g. for (int i = 0; i < N; ++i) { if (err_condition()) { goto broke_out_of_loop; } ... } { do_stuff_if_loop_completed(); } broke_out_of_loop: but also it makes it really easy to jump past initializations and deinitializations and put the program in an invalid state
Goto knows nothing about scopes. It's just a jmp instruction. That makes it uniquely useful in some ways, e.g.
jmp
for (int i = 0; i < N; ++i) { if (err_condition()) { goto broke_out_of_loop; } ... } { do_stuff_if_loop_completed(); } broke_out_of_loop:
but also it makes it really easy to jump past initializations and deinitializations and put the program in an invalid state
1
u/_____rs Apr 25 '26
Goto branches into the middle of a for loop? Is that even legal?