As others have said, this doesn't communicate the intent very well and one might need to think for a few seconds to understand the logic.
If you have to keep the maybeUpdateTime()
method as is, I would convert the loop into something like the following:
boolean needsUpdate = false;
do {
needsUpdate = maybeUpdateTime();
}
while (needsUpdate);
This communicates the intent perfectly, doesn't require modifying the maybeUpdateTime()
method, and doesn't force you to repeat some of the method's internal logic when calling it.
If you prefer a while
loop, this can be written as:
boolean needsUpdate = maybeUpdateTime();
while (needsUpdate) {
needsUpdate = maybeUpdateTime();
}