The issue is that not in is not valid GDScript syntax.
I believe this is what you want:
while not angle in range(-360, 360):
With that said, you seem to be going on a convoluted way to wrap the angle. You can do this for the same effect:
angle = wrapf(angle, -360, 360)
Using wrapf is very useful to normalize angle. For example, wrapf(angle, -180, 180) or wrapf(angle, 0, 360) for degrees or wrapf(angle, -PI, PI) or wrapf(angle, 0, TAU) for radians.
What does wrapf do? It wraps a float value around an interval. If the value is gone past one end of the interval, pretend it entered by the opposite end. For example wrapf(14, 0, 10) is 4, and wrapf(-4, 0, 10) is 6.
If I wanted to make a wrap function replacement in GDScript it would look like this:
func wrap(value:float, from:float, to:float) -> float:
var diff := to - from
return value - (diff * floor((value - from) / diff))
You don't have to. This is just for reference.