return
causes the function to exit as soon as its reached. You cannot return from a single call of a function multiple times.
The most straightforward solution is just to use a list comprehension, and return the result from it:
def MyFunction(Var1,Var2,RangeValues):
return [1-Var2 if (x-1-Var1) <= 0 else 1+Var2 for x in RangeValues]
or, make the function a generator using yield
:
def MyFunction(Var1,Var2,RangeValues):
for x in RangeValues:
if (x-1-Var1) <= 0:
yield 1-Var2
else:
yield 1+Var2
# Need to force the generator into a list to easily see the results
print(list(MyFunction(1,3,Range)))
Just learn how to use list comprehensions though (the first version), since they're the simplest. Once you begin advancing, generator functions (the second version) are a good topic to take up. I wouldn't use the second until you have a better understanding of Python. I showed it here because it's the closest to what you already have.
Also, don't use capitalized names for arbitrary variables. Plain variable names should be in lower case, separated by an underscore ("snake_case").