The “while” statement is used to loop while some expression evaluates to True.
It’s not very common, because most loops are used to iterate over some sequence of elements, in order to modify them, and there, the “for” statement is more convenient.
If you see a while statement used in blender, it would probably be in situations like:
new_random = last_random
while last_random == new_random:
new_random = random.randint(0, 3)
You don’t want to get the same random as the last, so you use while to try again, until you get something different.
As for the “return” statement: it’s used to return a value from a function. When you have a regular function like this:
def myFunc(arg):
r = arg + 1
print(r)
return # optional
The returned value is a NoneType object, or “None”, as it’s referred to in python.
Here:
def myFunc(arg):
r = arg + 1
return r
print(r)
The “r” object is returned, and print® is not executed.
I would recommend that you go through a python tutorial, where this is all covered (google “python tutorial” for relevant links).