Why doesn't this return the intended value

Then I suspect there’s a bug in your logic. The only way nothing can be returned from there is if the if condition in the loop is never true, i.e. the recursion isn’t run in some call. Semantically it’s the same as this:

function rebuilding_message(...)
     if isempty(encoded_string)
        return decoded_string
     else
        for i in key_encoding_array
             if length(encoded_string) >= i[3] && i[2] == encoded_string[1:i[3]]
                # recursive call, only hit when the if is true
                return rebuilding_message(...)
             end
        end

        return nothing
     end
 end

Like I said above, for loops don’t implicitly return any value (i.e. the branch then returns nothing). Does that make more sense to you?

2 Likes