3 ms·
We already have one built-in function that alters the control flow: panic. But I agree it's a bit weird.
by ngrilly 7y ago
We already have one built-in function that alters the control flow: panic. But I agree it's a bit weird.
- uryga 7y agotbh i don't know Go too well. as i understand it, `panic` can indeed hijack the control flow, i.e. stop it. but any function¹ can do that: just do `while 1 {}`! control flow won't return to the caller either way. so it's not that weird after all Ruby blocks can do non-local control flow, i.e. return from their surrounding function, but that's what makes them distinct from functions. --- ¹ in a turing-complete language (i'm a Haskell enthusiast, so please excuse the nitpicking :)
- ngrilly 7y agoA panic can be recovered with recover(), and thus the program can continue. While a function that does an infinite loop will halt the program and nothing else.