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
end
This 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
end
Now 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:
Here, 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.
I'm not sure the current exit code for
whilewhen 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.This 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:
Now if the condition failed to run (instead of ran and exited with a non-zero exit code), it would make sense for
whileto return non-zero:Here, it would make sense for
$statusto evaluate to non-zero after the loop.My problem is with a script or function that executes in a loop, an explicit
return/exit 0is 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.