What other approach do you guys know/use?
You can encapsulate your while loop in a function (and call this function where you had your while loop):
static void process(void)
{
// process
if (!success) return;
// process
if (!success) return;
// process
if (!success) return;
// process
}
Any halfway decent compiler (e.g., even gcc with optimizations disabled) will inline a static function if it is called once. (Of course some variables may have to be in the lexical scope of process function, in that case just provide them as parameters of the function).
Note that writing code from top to bottom instead of horizontally (e.g., your example with nested if) is called duffing. There is a nice article on the subject here:
“Reading Code From Top to Bottom”
Also, in the Linux kernel coding style there is a specific warning writinh against horizontal code:
“if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program”