First thing:
In the global scope, you want to define a function before you call it.
This explains why your first code doesn't work. Python hasn't defined the function yet and you're calling it before it has a chance to access it.
print("TRUE" if y>x else theloop())
# Python hasn't seen this when you call the function
def theloop():
    while y < x:
       print(y+1)
Second thing:
The code you wrote that runs only prints (y+1)... it does not actually increase y by 1.
Also, y is not accessible within the function so:
Define it locally before the while loop like this:
x = 10
def the_loop():
    # define y locally
    y = 0
    while y < x:
        # increases y by 1
        y += 1
        print(y)
print("true" if y > x else the_loop())
Pass it in as an argument if y might change:
x = 10
y = 0
# pass y in as an argument 
def the_loop(y):
    while y < x:
        # increases y by 1
        y += 1
        print(y)
print("true" if y > x else the_loop(y))
Use the global keyword (see this post)
y = 0
x = 10
def theloop():
    global y
    while y < x:
       y += 1
       print(y)
print("true" if y > x else the_loop())
Using global keyword actually changes the original variable and now y = 10 is accessible outside of the function.
More on globals here