while(1) .. break instead of goto
问题 I found the following code in a C program: while (1) { do_something(); if (was_an_error()) break; do_something_else(); if (was_an_error()) break; [...] break; } [cleanup code] Here while(1) is used as local emulation of "finally". You can also write this using goto s: do_something() if (was_an_error()) goto out; do_something_else() if (was_an_error()) goto out; [...] out: [cleanup code] I thought the goto solution is a usual idiom. I have seen several occurrences of this idiom in the kernel