6 ms·
This would achieve the same but is far more readable: while(status != SUCCESS) { status = syscall(...); // do something with status }
by Sahhaese 7y ago
This would achieve the same but is far more readable:
while(status != SUCCESS) {
status = syscall(...);
// do something with status
}
- taneq 7y agoOnly if status is initialised to something other than SUCCESS.
- blktiger 7y agoSo use a do-while instead.
- Izkata 7y agoAnd this introduces another bug: it'll run the loop body even if syscall fails the first time it's run.
- dpzmick 7y agoI've been going with this style for things like reading files (with retries) or any sort of loop that feels awkward. while (1) { int ret = ...; if (ret == ...) break; if (ret == some_other_condition) break; // additional termination conditions.... // do exactly one thing }
- Izkata 7y agoYour transformation has introduced a bug: the loop body will run once after success turns false.