As suggested by @slomo, make the loop more readable and prevent returning a garbage value to the caller from the previous implementation. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2232>