Skip to content

Use 'continue' keyword in preference to 'goto' where possible

Simon McVittie requested to merge smcv/dbus:goto-considered-unnecessary into master

In some more complicated loops, we do need to use 'goto' to exit from an inner loop, or to jump to cleanup or an increment of an iterator immediately before the next loop iteration. However, in these simple cases, jumping to a label immediately before the 'while' keyword is unnecessary: we can use an equivalent 'continue' statement for flow control.

This makes it easier for maintainers to notice the loops where we are doing something more complicated, which still use 'goto', and know that they need to pay more attention in those cases.


I noticed one instance of this while working on #413 (closed), but didn't want to put it on the critical path while under embargo.

Merge request reports