That is because of the function (method) which has a return value,
just for more explanation functions can have return type or void which is not return anything for the caller
so, here your function lookUpProfile(name, prop) returns string so in the function return keyword must have and return the value of the return contacts[x][prop];, or string return "No such property"; or return "No such contact";
for the Why part of your question, the loop provide the return keyword but take it like this, which is not an academic way of saying it but I do it anyway,
The compiler says "I know you have provided return but I don't know if it has any Run-time error and doesn't return the value at all". In C# compiler it shows you
Severity Code Description Project File Line Suppression State
string test()
{
for (int i = 0; i < 5; i++)
{
if (i == 3)
{
return i.ToString();
}
}
}
**Error CS0161 'ClassName.test()': not all code paths return a value**
in C# it counts as a Compiler error, meaning it doesn't let compile unless you fix that.
Basically, it doesn't let you in some compilers like C#, for guaranteeing the function returns a value.