-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
I'm not sure the current exit code for while when the loop evaluation condition returns non-zero makes sense. I understand that it passes through the value returned by the condition executable, but I'm not sure that a non-zero exit code accurately reflects the intent of the code, nor is particularly useful.
while foo
if bar
break
end
endThis loop can terminate with either a zero or non-zero exit code. But it's equal to the following, which can only terminate with a zero exit code:
while true
if not bar
break
end
endNow if the condition failed to run (instead of ran and exited with a non-zero exit code), it would make sense for while to return non-zero:
while does-not-exist
endHere, it would make sense for $status to evaluate to non-zero after the loop.
My problem is with a script or function that executes in a loop, an explicit return/exit 0 is needed to "override" the misleading nonzero exit code after the loop, which shouldn't (imho) ever be necessary unless a failure was detected and is being explicitly ignored.