When return should be used inside the fun. and inside the loop.?


I need help understanding when should Return be used inside a function and when it should be used inside a loop

n = [3, 5, 7]
def double_list(x):
    for i in range(0, len(x)):
        x[i] *=2
    return x
# Don't forget to return your new list!
print double_list(n)

In the exemple above - the function cause each n[index] to multiply by 2 and the Return statement is outside the loop.
When I put the return inside the loop - CodeCademy gave me an error (console did not).

def my_function(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
    return x

in the exemple above the return is inside the loop.

Can someone explain to me when will I want to use the Return inside and outside a loop?


The thing you should keep in mind....
if the Interpreter encounters a return statement
the function will be =exited=


Where do you learn that information? I find it hard to learn the big picture without knowing the little things.
You learn that on Computer Science courses? or you can find that kind of information online or in books?